If I have some documents inside a collection. In this format:
{posts: [{"name": "post1"},..., {"name": "postN"}]}
What is the equivalent of this function:
db.my_collection.update({}, { $set: {"posts.0.lastMod": new Date()}}, false, true)
But to update all the embedded documents instead of only position 0
? I have tried doing:
db.my_collection.update({}, { $set: {"posts.lastMod": new Date()}}, false, true)
But that just gave me an error already on the first document:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 28,
"errmsg" : "Cannot create field 'lastMod' in element {posts: [ALL MY ARRAY WAS PRINTED HERE]"