Search code examples
javascriptnode.jssails.jswaterlinesails-mongo

Sails.js waterline destroy "lower or equal" criteria


I'm trying to use the destroy method with a lower than in the request, and I can't make it to work.

Although, the find method returns some content with the exact same parameters.

Cars.find({userId: params.userId, accessDate: { '<=': new Date() }}, function (err, found) {
    console.log(found); //Returns an array with multiple entries.
}); 

Cars.destroy({userId: params.userId, accessDate: { '<=': new Date() }}); //Does nothing, the entries are not destroyed.

This is the content in my database returned by the first request:

[ { userId: '563c1c37be1ed48e7f8c6ada',
    accessDate: '2015-11-07T21:36:13.169Z',
    id: '563e60bd19667c52bd831182' },
  { userId: '563c1c37be1ed48e7f8c6ada',
    accessDate: '2015-11-10T05:04:01.850Z',
    id: '56416cb140112987ce6ec049' },
  { userId: '563c1c37be1ed48e7f8c6ada',
    accessDate: '2015-11-12T03:59:36.519Z',
    id: '5644009851503b42e589ecf1' } ]

Am I wrong somewhere? What should I do?

Thanks.


Solution

  •     Cars.find({userId: params.userId, accessDate: { '<=': new Date() }})
        .exec(function (err, found) {
    
        });
    
        Cars.destroy({userId: params.userId, accessDate: { '<=': new Date() }})
        .exec(function (err) {
    
        });
    

    Hope helpful