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.


Problem courtesy of: Masiar


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});
Solution courtesy of: Eve Freeman


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.