我有一个使用旧版本的查询:
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/