Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- x: 1,
- myarray: [
- {
- a: 1,
- b: 2,
- },
- {
- a: 1,
- b: 4,
- }
- ]
- }
- MyModel.update({x: 1, myarray.a: 1},
- {$set:
- {"myarray.$.b": 3}
- },
- function(err) {
- });
- db.collection.find({"x": 1, "myarray.a": 1}).forEach(function(doc) {
- doc.myarray.forEach(function(item){
- if(item.a == 1){
- item.b = 3;
- }
- });
- db.collection.save(doc);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement