im new with mongo and so far have no issue using it. Until i stuck at this. I need to push a document to an array inside an array. Can refer to json below.
{
'user_id':'{1231mjnD-32JIjn-3213}',
'name':'John',
'campaigns':
[
{
'campaign_id':3221,
'start_date':'12-01-2012',
'messages':
[
{
'message_id':211134,
'email':'[email protected]'
}
]
},
{
'campaign_id':3222,
'start_date':'13-01-2012',
'messages':
[
{
'message_id':315521,
'email':'[email protected]'
}
]
}
]
}
I want to push one document to an array of messages in a campaigns array(regardless ordering). Meaning that, i need to append new document to an array of messages. And all those messages is from inside another array or campaigns per user. Im using python so my code will be like this.
query = {"user_id" : "{1231mjnD-32JIjn-3213}", "campaigns.campaign_id": 3221}
message = {"message_id":4213122, "email":"[email protected]"}
op = {"$push" : {"campaigns.messages":message}}
mongo.TestDatabase.members.update(query, op)
There is no error upon execution. But the document seems to have no changes(no update made). What am i doing wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…