在数据库查询的时候使用cloudEnv_uid来验证是否为对应id(此写法依赖uni-id)
let count=await db.collection("XXXXX")
.where({
article_id:this._id,
user_id:'$cloudEnv_uid' ,
}).count()
console.log(count);
当时写的代码如下,因为需要验证多个条件,不是很清楚字符串应该怎么写,所以用的是官网上的写法:
然而出现了标题那样的报错,折腾了好久都没有进展,实际上这个问题在uniapp文档就有解答,在写字符串时:
db.collection('user').where('_id==$cloudEnv_uid').get()
而我上述代码应该是不能直接使用$cloudEnv_uid的,在写对象时:
db.collection('user').where({
_id: db.getCloudEnv('$cloudEnv_uid')
}).get()
所以改正后的代码应该为:
let count=await db.collection("XXXXX")
.where({
article_id:this._id,
user_id:db.getCloudEnv('$cloudEnv_uid') ,
}).count()
console.log(count);