PynamoDB: how to update an attribute in a ListAttribute of MapAttribute
I am learning how to use PynamoDB to work with AWS DynamoDB in my Python code. Here is what I have defined so far:
class OfficeEmployeeMap(MapAttribute): office_employee_id = NumberAttribute(hash_key=True) office_employee_direct_ids = UnicodeSetAttribute() class Office(Model): class Meta: table_name = 'OfficeModel' office_id = NumberAttribute(hash_key=True) employees = ListAttribute(of=OfficeEmployeeMap) Office.create_table(read_capacity_units=1, write_capacity_units=1)
Here is how I appended to the list of map attributes (employees
):
emp1 = OfficeEmployeeMap( office_employee_id=111, office_employee_direct_ids={"222"} ) Office( office_id=1 ).update( actions=[ Office.employees.set((Office.employees|[]).append([emp1])) ] )
And here is what I am seeing in the newly created DynamoDB table OfficeModel
:
Now I need to add another value, like 333
, to the set office_employee_direct_ids
where office_employee_id
== 111
, how can I do it with PynamoDB? Thanks for your help!