Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. {
  2. x: 1,
  3. myarray: [
  4. {
  5. a: 1,
  6. b: 2,
  7. },
  8. {
  9. a: 1,
  10. b: 4,
  11. }
  12. ]
  13. }
  14.  
  15. MyModel.update({x: 1, myarray.a: 1},
  16. {$set:
  17. {"myarray.$.b": 3}
  18. },
  19. function(err) {
  20. });
  21.  
  22. db.collection.find({"x": 1, "myarray.a": 1}).forEach(function(doc) {
  23. doc.myarray.forEach(function(item){
  24. if(item.a == 1){
  25. item.b = 3;
  26. }
  27. });
  28. db.collection.save(doc);
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement