I clearly don't understand how I update / insert a subdocument in an existing document. I tried the following:
query = aCollection.find_one({stuffToFind})
aCollection.update(query,
{"$set": {"subDoc" : {"1" : String, "2" : datetime.datetime.now(), "3" : otherString}}})
this only works one time but I want to constantly change the subDoc's Data 1,2 and 3 if this code is executed. find_and_modify also fails, because it seems to overwrite the whole document deleting all other fields but the id and those specified in update. Since I'm pretty new to MongoDB it would be nice if someone could give me a code example how to figure out my problem.
Edit: without the "$set" statement it remains unchanged as well on a second execution..
Edit2: this seems to work, eventhough I'm unable to edit the affected (JSON)document directly in MonjaDB anymore :D
aCollection.update(query(but this time not as a variable),
{"$set" : {"subDoc.1" : Sting, "subDoc.2" : datetime.datetime.now(), "subDoc.3" : otherString}})
I dont know, why this is working so maybe someone could explain what I did wrong..
Thanks in advance,
Codehai