【问题标题】:Buildfire - Trouble with Query SelectorsBuildfire - 查询选择器的问题
【发布时间】:2017-08-24 16:56:15
【问题描述】:

我有两个 unix 时间戳,一个开始时间 (startDate) 和一个结束时间 (endDate)。使用下面的 moment 函数为我提供了一天的开始/结束:

search = {
  "end": { "$lte": moment(endDate).startOf('day').unix() },
  "start": {"$gte": moment(startDate).startOf('day').unix() }
};

然后我将搜索传递给我的 buildfire 函数:

buildfire.publicData.search(search ,'routes', (err, res) => {})

我的 res 是一个对象数组,每个对象都有一个 data 属性和一个 startend 属性里面:

res = [
  {
    data: {
      end: 1503554370297,
      start: 1503554368711
    }
  }
]

所有结果都返回,没有任何内容被过滤。

【问题讨论】:

    标签: buildfire


    【解决方案1】:

    这里是 docs 数据存储搜索 https://github.com/BuildFire/sdk/wiki/How-to-use-Datastore#buildfiredatastoresearchoptions-tag-optional-callback

    我相信您没有正确发送过滤器。

    您正在发送:

    search = {
      "end": { "$lte": moment(endDate).startOf('day').unix() },
      "start": {"$gte": moment(startDate).startOf('day').unix() }
    };
    buildfire.publicData.search(search ,'routes', (err, res) => {})
    

    而且应该更像

    var options = {
      "filter":{
            "$json.end": { "$lte": moment(endDate).startOf('day').unix() },
            "$json.start": {"$gte": moment(startDate).startOf('day').unix() }
      }
    };
    buildfire.publicData.search(search ,'routes', (err, res) => {})
    

    基本上,因为您的options 对象中的filter 属性是undefined,它会返回所有内容

    【讨论】:

    • 感谢工作。我在这里查看文档 (github.com/BuildFire/sdk/wiki/Search-Operators)。他们不使用 $json 也不显示 filter 作为键,但我想我应该假设使用过滤器。 Mongo 文档有点让我失望
    • 能否举个例子说明如何使用$where
    • 看起来像{filter:{ $where: "$json.credits == $json.debits" }}
    • 我正在尝试类似的方法,但出现 400 错误。 {"code":"BADREQUEST","message":"搜索数据时出错"}
    • 你能把你的选项对象粘贴到这里以便我查看
    猜你喜欢
    • 2013-06-08
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-08
    • 2011-07-27
    • 1970-01-01
    • 2020-01-06
    相关资源
    最近更新 更多