MongoDb : How to insert additional object into object collection?
As other mentioned, The structure you want is not valid. I recommend the following structure for your owner document:
{
"_id" : ObjectId("51c9cf2b206dfb73d666ae07"),
"firstName" : "john",
"lastName" : "smith",
"ownerEmail" : "[email protected]",
"camps" : [
{
"name" : "cubs-killeen",
"location" : "killeen"
},
{
"name" : "cubs-temple",
"location" : "temple"
}
],
"instructors" : [
{
"firstName" : "joe",
"lastName" : "black"
},
{
"firstName" : "will",
"lastName" : "smith"
}
]
}
and then
db.stack.update(
{ ownerEmail: "[email protected]" },
{
$push: {
camps: { name: "cubs-killeen", location: "some other Place" }
}
}
);
Having this, you can add camps like this:
Hope it helps.