Mongodb聚合=[查找-$lookup-$match-$check和$update]
我是 Mongodb 初学者,我在数据库中有两个集合(关系):
供应商集合:
首先,我需要使用电子邮件搜索文档,然后在子文档中找到 Expired 字段值为 false 的 stats_ID并使用这些 stats_id 搜索另一个集合**
{
"_id": {
"$oid": "6229d3cfdbfc81a8777e4821"
},
"stats": [
{
"stats_ID": {
"$oid": "62289ded8079821eb24760e0"
},
"New": false,
"Expired": false
},
{
"stats_ID": {
"$oid": "6228a252fb4554dd5c48202a"
},
"New": false,
"Expired": false
},
{
"stats_ID": {
"$oid": "622af1c391b290d34701af9f"
},
"New": false,
"Expired": false
}
],
"email": "[email protected]"
}
数据集合:
stats_ID(来自第一个集合结果)应与以下文档(例如,我只添加了一个文档)与字段 _id 匹配,并检查创建日期比今天的日期多。如果创建日期大于数据收集的今天日期_,则 stats_id(供应商收集中)的 Expired 值应更改为 true。
[
{
"_id": {
"$oid": "62289ded8079821eb24760e0"
},
"Main_ID": "JB-456765",
"Expired": {
"$date": "2022-03-15T18:30:00Z"
}
}
]
尝试了很多方法,但没有得到想要的结果
I am a Mongodb beginner, I have two collections(relational) in database:
vendors collection:
First, I need to search the document with email and then find the stats_ID which Expired field value is false in the subdocument and search the another collection with these stats_id**
{
"_id": {
"$oid": "6229d3cfdbfc81a8777e4821"
},
"stats": [
{
"stats_ID": {
"$oid": "62289ded8079821eb24760e0"
},
"New": false,
"Expired": false
},
{
"stats_ID": {
"$oid": "6228a252fb4554dd5c48202a"
},
"New": false,
"Expired": false
},
{
"stats_ID": {
"$oid": "622af1c391b290d34701af9f"
},
"New": false,
"Expired": false
}
],
"email": "[email protected]"
}
Data collection:
the stats_ID(from first collection result) should match with below document(for example, I added only one doc) with the field _id and check the creation date is more than todays date. if the creation date is greater than todays date of the data collection _,then the Expired value of stats_id(in vendor collection) should change to true.
[
{
"_id": {
"$oid": "62289ded8079821eb24760e0"
},
"Main_ID": "JB-456765",
"Expired": {
"$date": "2022-03-15T18:30:00Z"
}
}
]
I have tried with many methods but not getting the desired result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我了解您希望如何更新您的
vendors
文档。这是一种方法。在 mongoplayground.net 上尝试一下。
I think I understand how you want to update your
vendors
docs. Here's one way to do it.Try it on mongoplayground.net.