Update multiple records in a Model with Waterline on Mongodb

727 views
Skip to first unread message

Sails Junior

unread,
Apr 28, 2017, 3:58:11 PM4/28/17
to sails.js

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

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

var status = {status: 'accepted'}

I tried this:

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


But the updatedbooks is empty. 


When I have the bookCriteria=['58b2e58','5903703'] like this, it will update all those books with the given ID's, but I want only update books with the status = pending

Robert Main

unread,
Apr 28, 2017, 5:15:11 PM4/28/17
to Sails Junior, sails.js
Not to be "that guy", but criteria is already a plural...

Sails Junior

unread,
May 1, 2017, 7:53:17 AM5/1/17
to sails.js, tren...@gmail.com
Came here to learn Sails.js - learnt English. :D haha thanks! 


Here is my answer to my problem, its not the best way, but its a working way:

Reply all
Reply to author
Forward
0 new messages