Insert A Json Subdocument In A Mongodb Document In Python
I want to insert a subdocument in a document that I have in my mongoDB database. I want to retrieve with a find a subdoc and then to add something there. My code for retrieving the
Solution 1:
Try this:
collection.update_one({"user_id": "13245"},{"$set": temp_json})
As I can understand your issue, you want to insert multiple item_id
. You can do it like this:
collection.update_one({"user_id": "13245"},{"$set": {"item_id.111111":temp_json.get('item_id').get('111111')}})
Check the documentation for inserting embeded documents: Set Fields in Embedded Documents
Post a Comment for "Insert A Json Subdocument In A Mongodb Document In Python"