python - add a new value to array while keeping existing one -
i have below example of data:
{ "id": "2", "items": { "3" : { "blocks" : { "3" : { "txt" : 'xx' } } }, "4" : { "blocks" : { "1" : { "txt" : 'yy'}, "2" : { "txt" : 'zz'} } } } }
i want make looks below example data. append new value items.3.blocks.3.txt while keeping existing value of it:
{ "id": "2", "items": { "3" : { "blocks" : { "3" : { "txt" : 'xx, tt' } } }, "4" : { "blocks" : { "1" : { "txt" : 'yy'}, "2" : { "txt" : 'zz'} } } } }
i run below did not make difference
dbx.test.update({"_id": objectid("5192264c02a03e374e67d7be")}, {'$addtoset': {'items.3.blocks.0.txt': 'tt'}}, )
what should correct syntax, appreciated... regards
you need use '$push' instead of '$addtoset':
dbx.test.update({"_id": objectid("5192264c02a03e374e67d7be")}, {'$push': {'items.3.blocks.0.txt': 'tt'}}, )
Comments
Post a Comment