0

Recently I asked for $in when using mongoose.someModel.find({$in}) https://stackoverflow.com/questions/11839765/whats-wrong-with-in-in-mongoose"

After restarting node for a few times it work correctly as it was originally. But now I found next

dbQueries.update({_id: {$in: req.body.data}, authorId: req.user._id}, {deleted: true}, function onUpdate(err){
            if(err) {
                console.log(err);
                res.json({epicFail: 'ERR_RestrictedAccess'});
                return; 
            }
            res.json({});
        });

I found that it updates only first found document! What is happening? I use the last node version and the last of mongoose 2. Moreover it works correctly with mongo-native!!!

Community
  • 1
  • 1
Roman
  • 215
  • 1
  • 2
  • 10

1 Answers1

4

I think, you need to add 'multi' option in your query.

dbQueries.update({_id: {$in: req.body.data}, authorId: req.user._id}, {deleted: true}, { multi: true }, function onUpdate(err){
    if(err) {
        console.log(err);
        res.json({epicFail: 'ERR_RestrictedAccess'});
        return; 
    }
    res.json({});
});
Vadim Baryshev
  • 25,689
  • 4
  • 56
  • 48