Search code examples
node.jssails.jswaterline

Waterline (Sails.js). Rows with 'updatedAt' greater than a given value


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.


Solution

  • 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);
        });