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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -