I want to get the new rows from a model. The rows that have been created after a given date. The query should be very easy:
where updatedAt >= givenDate
But it's not working :(
My code:
// Date from client
var lastDate = req.param("date");
// Parse date with moment? I have tried with and without this.
lastDate = moment(lastDate).format('YYYY-MM-DD hh:mm:ss');
var query = Message.find().where({
updatedAt: {
'>=': lastDate
}
});
query.exec(function(err, messages) {
// I get ALL the messages, :(
res.send(messages);
});
Thanks in advance.
The Sails framework is built by a web & mobile shop in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!
For a better experience on sailsjs.com, update your browser. sails.config.* The Sails framework is built by a web & mobile shop in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects.
Waterline is a new kind of storage and retrieval engine. It provides a uniform API for accessing stuff from different kinds of databases, protocols, and 3rd party APIs.
To update a particular record, use .updateOne (). await User.update ( { name: 'Pen' }) .set ( { name: 'Finn' }); sails.log ( 'Updated all users named Pen so that their new name is "Finn". I hope they like it.' );
Solved.
I created a Date instance and passed that to the where clause:
// Date from client: Date in MS (new Date().getTime())
var lastDate = req.param("date");
// Create date
lastDate = new Date(lastDate);
var query = Message.find().where({
updatedAt: {
'>=': lastDate
}
});
query.exec(function(err, messages) {
// I get ALL the messages, :(
res.send(messages);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With