2

I have a collection in MongoDB that contains a list of objects. Each object has an array of "updaters" which are objects with a field that I want to update. One of the updaters in that array needs a description updated. How can i update just the descrption of the the updater object, that I know "updaterId" of.

enter image description here

Update:

It appears to me that setting the flag multi: true will do the trick in Mongo 2.2+.

db.configurations.update(
  {"updaters.updaterId": "90391154-67BB-452E-A1A7-A07A98B94F86"},
  {$set: {"updaters.$.description": "This tool will prevent users from Unloading Linked Revit files for \"all users\" which causes such Linked File to be unloaded by default when opening project."}},
  {multi: true}
)
0

1 Answer 1

2

You can update the description updaterId like this:

db.collection.update( {"updaters.updaterId" : updaterId } ,
               {$set : {"updaters.$.description" : "My description"}} ,
               false ,
               true);

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Doesnt this only update a single entry? I have multiple objects with the same updaterId and I am trying to change them all at once. Is that possible?
For now no. Using $in also it will only update the first id in array.
So I suggest to you use loop. If your dataset is huge, You can go with mongo bulk update.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.