在云函数中操作数据库时, 使用_.gt为何会报错?

发布于 6 年前作者 pengwei3935 次浏览最后编辑 6 年前来自 issues
function resetLottery(){
  console.log("resetLottery start")
  //清空ticket表
  cloud.database().collection('ticket')
    .where({
      time: _.gt(10)
    })
    .get()
 
  .then(res=>{
    console.log("resetLottery",res)
  })
  .catch(err=>{
    console.log("resetLottery", err)
  })
 
}

代码是这样的,一样的_.gt在云开发数控制的可以正常使用,但在云函数调用时出现了如下报错

getConfig fail ReferenceError: _ is not defined

是我哪里写得不对吗?求解答

2 回复
lwen
lwen1 楼6 年前

解决了,是第三个问题,非常感谢

leihu
leihu2 楼4 年前

_没定义

cloud.init()

const db = cloud.database();

const _ = db.command

确保有这三个东西