0

desperately I look for a solution of a very simple problem. I use NINJA and Robomongo as environment.

I want to add a collection to an existing one, all in the same FOR loop:

existing:

  {
    "_id" : ObjectId("54608d9f35121b0e18aa01b2"),
    "level1" : {
        "item1" : 200.55,
        "item2" : "001",
        "item3" : 708874,
     }
  }

want to get:

{
    "_id" : ObjectId("54608d9f35121b0e18aa01b2"),
    "level1" : {
        "item1" : 200.55,
        "item2" : "001",
        "item3" : 708874,
        "level2" : {
            "item4" : 200.55,
            "item5" : "001",
            "item6" : 708874,            
        }

    }
}

I tried UPDATE with $set (unset=True), $addToSet etc. Problem seems that it's not an array.

Thanx for help

1 Answers1

0

found the solution in this forum: Pymongo how to properly use $push to update an existing document The first answer was

This query works.

db.foo.update({"node": "denver"}, {"$set": {"enc.classes.boulder": ""}}

And this works in my case! Thanx all

Community
  • 1
  • 1