如何在 docpad 中组合查询?

How to combine queries in docpad?

我只需要获取上周的帖子。我在 Documentation and for tests I use Query-Engine demo 中找不到使用此代码的示例:

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

如何获取此切片中的帖子?

正确答案如下:

    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