云函数查询:如何按照时间查询?
发布于 5 年前 作者 itao 4198 次浏览 来自 官方Issues

数据库字段支持 Date 类型。

但文档(https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/query.html ) 提供的查询指令,对时间貌似不好使,如:

// 入库
db.collection('orders').add({
    data: {
      openId,
      createdAtnew Date(), // 时间类型
    },
  });

// 查询
const DAY30 = 1e3 * 60 * 60 * 24 * 30;
// 获取订单列表
const getOrderAction = (event, openId) => {
  return db.collection('orders').where({
    openId,
    createdAt: _.gt(new Date(+new Date() - DAY30)),
  }).get();
};
回到顶部