云函数 在数据库聚合阶段使用match函数,做日期处理就会报错?
发布于 6 年前 作者 fpeng 6936 次浏览 来自 问答
db.collection('xunlian')
          .aggregate()
          .match({
            qiantao_id: 'xxx', 
            time: _.gt(new Date("2020-02-08 00:00:00")).and(_.lt(new Date("2020-02-08 23:59:59")))
          }).end()

总是报错:"[InvalidParameter] Check request parameter fail. Please check your request, but if the problem cannot be solved, contact us.; "

为了测试什么问题,

1:我把 time过滤条件注释掉, 结果:程序正常

2: time: _.gt(new Date("2020-02-08 00:00:00")) 这样写也有同样报错,看来和 and 没有关系

3:我把time拿到小程序端执行 结果也正常 (说明这个time过滤语法没有问题)

    productCollection.where({
      createTime: _.gt(new Date(strtime)).and(_.lt(new Date(endtime)))
    }).get({
      success: function(res) {
        console.log(res.data)
      }
    })
//这个是直接操作的数据库,没有做数据库的聚合操作

但是他们2个在一起就报错了…

我也不知道是我的问题还是官方这里有bug 不知道是不是数据库聚合阶段 才有这个问题,

反馈出来,看看官方能否帮忙看看

2 回复

感觉问题出在match里,match里应该是一个query,而不能是好几个key-value pair,如果有好几个条件,应该先and然后传入match。

参考这篇:

https://developers.weixin.qq.com/community/develop/doc/000860ca140fd87ab5e8bd7075b400?highLine=%25E4%25BA%2591%25E5%2587%25BD%25E6%2595%25B0%2520%25E6%259F%2590%25E6%259C%2588

server.Date的坑,建议用绝对时间;

回到顶部