【问题标题】:How to combine queries in docpad?如何在 docpad 中组合查询?
【发布时间】:2023-03-24 10:51:01
【问题描述】:

我只需要获取上周的帖子。我在Documentation 中找不到示例,对于测试我使用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

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

【问题讨论】:

    标签: docpad query-engine


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2018-03-24
      • 2015-06-25
      • 1970-01-01
      • 2012-03-21
      • 2012-11-01
      相关资源
      最近更新 更多