0

我只需要获得上周的帖子。我在文档中找不到示例,对于测试,我使用Query-Engine 演示和以下代码:

models = [
        title: 'WRONG: Future'
        date: new Date("2015-05-23")
    ,
        title: 'Correct 1'
        date: new Date("2015-05-22")
    ,
        title: 'Correct 2'
        date: new Date("2015-05-20")
    ,
        title: 'WRONG: Old'
        date: new Date("2015-05-15")
]

max_date = min_date = new Date("2015-05-22");
min_date.setDate(min_date.getDate() - 7);

result = queryEngine.createCollection(models)
    .findAll({
        $and: {
            date: {
                $lte: max_date
            },
            date: {
                $gt: min_date
            }
        }
    }).toJSON()

return result

如何获得此片段中的帖子?

4

1 回答 1

1

这是正确的答案:

    models = [
        title: 'WRONG: Future'
        date: new Date("2015-05-23")
    ,
        title: 'Correct 1'
        date: new Date("2015-05-22")
    ,
        title: 'Correct 2'
        date: new Date("2015-05-20")
    ,
        title: 'WRONG: Old'
        date: new Date("2015-05-15")
]

max_date = new Date("2015-05-22");
min_date = new Date(max_date.getTime() - 7*24*60*60*1000);

result = queryEngine.createCollection(models)
    .findAll({
        date: {$lte: max_date, $gt: min_date }
    }).toJSON()

return result
于 2015-05-22T08:20:19.733 回答