[英]Update field of a collection based on another collection - MongoDB
I have two collections The structure of collection A is我有两个 collections 集合 A 的结构是
{
id:
product:
}
The structure of collection B is集合 B 的结构是
{
id:
product:
status:
}
I want to update collection B like if a product exists in collection A, then it will set status 1 to the corresponding document of collection B.我想更新集合 B,就像集合 A 中存在产品一样,它会将状态 1 设置为集合 B 的相应文档。
The SQL syntax would be like SQL 语法就像
UPDATE B SET B.STATUS = 1 WHERE B.PRODUCT IN (SELECT PRODUCT FROM A);
I just need to do the same in MongoDB.我只需要在 MongoDB 中做同样的事情。 Thanks in advance.提前致谢。
In MongoDB 4.2 you can do this with aggregation.在 MongoDB 4.2 中,您可以通过聚合来执行此操作。
status: {$literal:1}
$项目status: {$literal:1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.