小程序云开发where条件怎么根据时间筛选
发布于 4 年前 作者 junzhu 11302 次浏览 来自 官方Issues

小程序云开发过程中,碰到需要查询大于或小于某个时间的数据,该如何写where条件?

db.collection(...).where(???)

where里现在只会用条件 key:val 即key=val

1 回复

可以使用db.command.gte

查询筛选条件,表示字段需大于或等于指定值。可以传入 Date 对象用于进行日期比较。

let curDate = new Date();
const _ = db.command
db.collection('todos').where({
  progress: _.gte(curDate)
})
.get({
  success: console.log,
  fail: console.error
})

具体参考微信官网文档:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-client-api/database/command.gte.html

回到顶部