Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. {
  2. _id : ...,
  3. other_stuff ... ,
  4. my_array : [
  5. { ... old content A ... },
  6. { ... old content B ... },
  7. { ... old content C ... }
  8. ]
  9. }
  10.  
  11. {
  12. _id : ...,
  13. other_stuff ... ,
  14. my_array : [
  15. { ... old content A ... },
  16. { ... NEW content B ... },
  17. { ... old content C ... }
  18. ]
  19. }
  20.  
  21. db.my_collection.update(
  22. {_id: ObjectId(document_id), my_array.1 : 1 },
  23. {my_array.$.content: NEW content B }
  24. )
  25.  
  26. db["my_collection"].update(
  27. { "_id": ObjectId(document_id) },
  28. { "$set": { 'documents.'+str(doc_index)+'.content' : new_content_B}}
  29. )
  30.  
  31. db.my_collection.update(
  32. {_id : "document_id"},
  33. {$set : {"my_array.1.content" : "New content B"}}
  34.  
  35. db.my_collection.update(
  36. {_id: ObjectId(document_id), my_array.1 : 1 },
  37. { $set: { "my_array.$.content" : "NEW content B" } }
  38. )
  39.  
  40. db.my_collection.update(
  41. {_id: ObjectId(document_id), my_array : { ... old content A ... } },
  42. { $set: { "my_array.$.content" : "NEW content B" } }
  43. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement