云函数数据库查询时关键字为变量的方法?

发布于 5 年前作者 ccui10200 次浏览最后编辑 5 年前来自 ask

db.collection('tableName').where({

_id:"ids",

}).get()

如果 我用js文件中的函数调用云函数查询时,_id,这个参数能否从event获取?也就是说,我的关键字通过JS中的代码指定的。

return await db.collection(event.tabName)where({event.txt:event.value}).get()

想要实现这样的功能怎么做?

2 回复
leigao
leigao1 楼5 年前
.where({
  [event.txt]: event.value
})
yinwei
yinwei2 楼10 个月前

[]