mongodb - 可以匹配填充的嵌套数组吗?
问题描述
是否可以使用带有猫鼬的常规 .findOne 函数对填充数组中的值进行条件匹配?
我有一个模型(Foo),它引用了另一个模型(协议),它有一个我填充的数组。
在填充函数中,我想使用match
“查询”仅根据此条件填充数据,但我无法让它工作。甚至可以match
在填充数组中使用吗?如果有填充对象,我对匹配没有问题,但对数组没有问题。
我只想isLatestVersion
在填充数据设置为 true 的时间/地点填充。任何指针?
我尝试过使用位置运算符、不同的语法等等,但没有任何效果。例如
'agreementInfo.$.isLatestVersion': true,
'agreementInfo.$[0].isLatestVersion': {$eq: true},
etc etc..
填充查询
await Foo.findOne(query)
.populate([{
....
path: 'agreements.songComposition',
match: {
'agreementInfo.isLatestVersion': true,
},
.....
},
},
....
人口模型(Foo)
...
agreements: {
...
songComposition: { type: mongoose.Schema.Types.ObjectId, ref: 'Agreement' },
},
填充模型(协议)
...
type: String,
agreementInfo: [
{
...
createdAt: { type: Date, default: Date.now },
isLatestVersion: Boolean,
...
}
]
解决方案
推荐阅读
- audio - 修改一些代码以将 ffmpeg / concat 不同的音频格式转换为 1 个长 WAV 文件
- reactjs - 为什么 setState 不改变值?
- kubernetes - GCP 上的 Kubernetes 集群缺少编辑权限
- sql - SQL - 将时间序列事件转换为开/关对(处理可能丢失的开或关)
- python - Python请求模块不遵循重定向文件下载
- javascript - javascript中类内的引用类型未按预期工作
- javascript - 如何用 js 定义数学值,然后将这些值相乘?
- iis - VS 2017 - Web 应用程序项目 [MyProject] 配置为使用 IIS。您无权访问 IIS 配置文件
- jquery - 带有 django 的 JQuery AJAX 获取 csrf 错误 403
- r - Rmarkdown 中一组特定行的 Calibri 字体