【发布时间】:2018-11-24 11:42:51
【问题描述】:
我希望在 MongoDB 中更新我的对象,如下所示
来自
{
"_id" : BinData(0, "vcbcbcbcvbdfsdgbbdvZNImOMQM6g=="),
"mypath" : "/sample/old/path/content/a/b",
"report_suite" : "mongo",
"target_s" : "/sample/old/path/content/c/d",
"topic_s" : "feed",
"id" : "/sample/old/path/content/retrieved/d4076995-f8a7-4b9f-912b-6f251a2fddcb",
"timestamp" : NumberLong(1527875028199)
}
到
{
"_id" : BinData(0, "vcbcbcbcvbdfsdgbbdvZNImOMQM6g=="),
"mypath" : "/sample/new/path/content/a/b",
"report_suite" : "mongo",
"target_s" : "/sample/new/path/content/c/d",
"topic_s" : "feed",
"id" : "/sample/new/path/content/retrieved/d4076995-f8a7-4b9f-912b-6f251a2fddcb",
"timestamp" : NumberLong(1527875028199)
}
基本上所有具有路径 /sample/old/path/content 到 sample/new/path/content 的字段值
请对此提供帮助。
我试过了
db.content.updateOne(
{ id:"/sample/old/path/content/retrieved/d4076995-f8a7-4b9f-912b-6f251a2fddcb" },
{
$set: { "target_s": "/sample/new/path/content/c/d" }
}
)
但是,我不想将“/sample/new/path/content/c/d”作为值,而只是将“/sample/old/path/content”替换为“/sample/new/path/内容”和其他其余部分相同
【问题讨论】:
标签: mongodb