Friday, 28 April 2017

Update multiple records in a Model with Waterline on Mongodb

Given is an array with book objects, where each status has to be updated:

var books = [ 
              { id: '58b2e58', status: 'pending' },
              { id: '5903703', status: 'pending' } 
                ]

var status = {status: 'accepted'}

I tried this:

Book.update(books, status).exec(function afterwards(err, updatedbooks) {
            if (err) {
                res.json(err)
                }
            console.log("updatedbooks:", updatedbooks);
});

but the 'updatedbooks' log is empty. When checking in mongodb, the books are there, I can find them with Book.find(books);



via PomeGranate

No comments:

Post a Comment