How to Update Multiple Array Elements in mongodb

UPDATE:
As of Mongo version 3.6, this answer is no longer valid as the mentioned issue was fixed and there are ways to achieve this. Please check other answers.


At this moment it is not possible to use the positional operator to update all items in an array. See JIRA http://jira.mongodb.org/browse/SERVER-1243

As a work around you can:

  • Update each item individually
    (events.0.handled events.1.handled
    …) or…
  • Read the document, do the edits
    manually and save it replacing the
    older one (check “Update if
    Current”
    if you want to ensure
    atomic updates)

Leave a Comment