【发布时间】:2021-12-29 16:12:46
【问题描述】:
我一定要用Mongo4.0。
我有一个嵌套对象。
{
_id:1,
route:'abc',
children:[
{
_id:2,
parentRoute:'abc',
currentRoute:'xyz',
route:'abc/xyz'
}]
}
假设 _id:1,如果路由从 'abc' 更新为 'mno' ,那么所有子节点都应该更新他们的 parentRoute 和路由。
{
_id:1,
route:'mno',
children:[
{
_id:2,
parentRoute:'mno',
currentRoute:'xyz',
route:'mno/xyz'
}]
}
随意提出不同的方法!! 我什至想到了 Regex $replaceOne,但我再次遇到了 Mongo4.0 实施的困难。
【问题讨论】:
-
this kind of update 你在找什么吗?
-
@ray "route": "abc/xyz" 也应该更新为 "route";"mno/xyz"。此外,这种方法在 mongo4.0 中是否有效?
-
This 是我能得到的最接近的。对于Mongo 4.0,由于$merge和update with aggregation pipeline不可用,我认为你需要坚持旧的js update method
-
@ray 感谢您的努力。
标签: mongodb api mongoose mongodb-query