【问题标题】:Waterline (Sails.js). Rows with 'updatedAt' greater than a given value水线(Sails.js)。 'updatedAt' 大于给定值的行
【发布时间】:2014-08-11 17:42:31
【问题描述】:

我想从模型中获取 new 行。在给定日期之后创建的行。查询应该很简单:

其中 updatedAt >= givenDate

但它不起作用:(

我的代码:

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

提前致谢。

【问题讨论】:

标签: node.js sails.js waterline


【解决方案1】:

解决了。

我创建了一个 Date 实例并将其传递给 where 子句:

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

【讨论】:

  • 嘿,不错的选择,但时间呢?尝试过做同样的事情,但只是用时间而不是日期?我不能这样做,即使我不知道如何发送像19:11:23 这样的值并将其解析为存储在 mongoldb 数据库中。知道如何解决吗?
猜你喜欢
  • 2014-12-14
  • 1970-01-01
  • 2015-01-03
  • 1970-01-01
  • 1970-01-01
  • 2014-08-19
  • 2014-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多