jeudi 12 mars 2015

MongoDB findAndModify: >>> find and update object in document's array


Vote count:

0




Before I made some similar operation but I had only one document in collection and it looked like this:


Pure Mongo:



db.table.findAndModify({query: {"features.properties.title":"OldValue"}, update: {$set:{"features.$.properties.description":"NewValue"}}})


Express:



collection.findAndModify({"features.properties.title": title}, [],
{$set: {"features.$.properties.explanation":explanation,
"features.$.properties.completion":completion}}, {},
function (err, result) {

if (err) throw err;
}
);


Now I try to look after object in document's array and update it.


Syntax bellow give me element i want, but i don't know how to use it in findAndModify and update this object



db.users.find({"username":"username"},{"array":{$elemMatch:{"name":"name"}}})


asked 32 secs ago

IOR88

136






MongoDB findAndModify: >>> find and update object in document's array

Aucun commentaire:

Enregistrer un commentaire