i have the following strucure:
{
'name':'something',
'commens':{
'value':'something'
}, {
'value':'something else'
}
}
My question is, how can i insert/update those subdocuments?
i have the following strucure:
{
'name':'something',
'commens':{
'value':'something'
}, {
'value':'something else'
}
}
My question is, how can i insert/update those subdocuments?
If you are using the MongoDB console, you will have to use the $ positional operator to update embedded documents.
db.yourCollection.update({ "_id" : ObjectId("4a33289ae89489"), "commens._id" : ObjectId("32321eae20fc603aee49124") }, { "$set" : { "commens.$.value" : "something else" } })
I am assuming 'comments' is an array, otherwise the example you posted in not a valid JSON/BSON. For array operations, you can look : http://docs.mongodb.org/manual/reference/operator/update-array/
In update query only, you can do upsert, which will insert the document if it don't exists.