位置投影不能与mongo4.4中的文字错误一起使用



我有一个使用旧版本的查询:

await this.model.findOne({ userEmail, 'environments.envId': envId },{ 'environments.$': envId })

但我在environments.$中出现错误。我在网上找不到任何与此错误有关的内容。

使用$projections只能使用一个数字。以下代码将起作用:

await this.model
.findOne({
userEmail, 
'environments.envId': envId 
},
{ 
'environments.$': 1 
})

此处提供更多信息:https://docs.mongodb.com/manual/reference/operator/projection/positional/

最新更新