小程序云函数collection参数能不能使用变量
发布于 6 年前 作者 ping73 7522 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)

exports.main = async(event, context) => {

console.log(event.id, event.name)

const dbName = event.name

// 先取出集合记录总数

const countResult = await db.collection(dbName).where({

areaid: _.eq(event.id)

}).count()

}

上面是部分代码,会报错误

Reduce of empty array with no initial value

dbName用具体的数据库名就能正常运行

请问是否这个命令不能使用变量代替数据库名?

1 回复

Reduce of empty array with no initial value

你发的代码没问题,这个错误是reduce的初始值未设置,你代码里用了reduce吧

回到顶部