unicloud
的 _id
在数据库中存储的是 ObjectId
格式,并不是 string
格式。
在 match
或者 where
的时候,能够以直接用字符串进行匹配,如下:
// 普通查询
db.collection('user')
.where({
_id: uid,
}).get()
// 聚合查询
db.collection('user').aggregate()
.match({
_id: uid,
}).end()
甚至在 lookup
函数中也可以直接写。
但是,要注意。如果你想要 project
进行处理时, _id
又会重新返回到 ObjectId
格式。
也就是说,云开发中所有传入的 24 位字符串全部被认为 ObjectId
并且进行了自动转换。
相比 mongdb
原生的许多方法, unicloud
和腾讯云开发却又没有跟进。