在云函数中操作数据库时, 使用_.gt为何会报错?
发布于 4 年前 作者 pengwei 3605 次浏览 来自 官方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 回复

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

_没定义

cloud.init()

const db = cloud.database();

const _ = db.command

确保有这三个东西

回到顶部