Masiar
Masiar

Reputation: 21352

Mongoose updating documents: updates just the first one

I have a strange problem. I do this query in a node.js server using mongoose: Transaction.update({username : user.username}, {$set: { pending : true }} ... that basically should set in all the items with the username equal to user.username the attribute pending: true. The problem is that it only sets it to the first element it finds. Is that possible? Because I have always 2 elements in my DB and sometimes one is pending, sometimes the other but not both of them.

Thanks!

Upvotes: 1

Views: 268

Answers (1)

Eve Freeman
Eve Freeman

Reputation: 33155

The way mongoose/mongodb work is that you must specify when you want to allow a multi update, via the options parameter:

Transaction.update({username : user.username}, {$set: { pending : true }}, {multi: true});

Upvotes: 4

Related Questions