0

I am wokring with mongoose in Nodejs. I have strange problem that when I am trying to update the objects in DB by ids, only the first 'id' is being updated. Here is my code:

user.update({'_id': { $in: req.body.ids}}, 
{ $addToSet: { forms: { $each: req.body.forms} } })

I checked the array of ids and there are 3 of them, but I get the response from the update:

{ n: 1,
nModified: 1,
...

1 Answers1

1

User multi: true option of update method. By default only first document found by the query is updated.

user.update({'_id': { $in: req.body.ids}}, 
{ $addToSet: { forms: { $each: req.body.forms} } }, {multi: true})
cheekujha
  • 781
  • 4
  • 12