我在mongodb中有如下文档:
{
"_id":"563f480fb5c2187503eefc1a",
"ownerBy":"56335521f2f4a3150349d78d",
"data": {
"username1":"76561198060520554",
"username2":"76561198060520554",
"username3":"76561198060520554",
"username4":"76561198060520554",
"username5":"76561198060520554"
},
"__v":0
}
客户希望将username1
的值更新为以下newValue
:
{ newValue: 'as76561198060520554',
id: 'username1',
column: 'selectable'
}
如何找到字段_id
并将其替换为newValue
?
答案 0 :(得分:0)
鉴于我们掌握的信息很少,这可能是您正在寻找的信息!
收藏将是您收藏的名称!
Collection.update({
"_id":"563f480fb5c2187503eefc1a"
},
{$rename: {"_id" : "newValue"}},
{$set: {
newValue: 'as76561198060520554',
id: 'username1',
column: 'selectable'
}},
{"upsert": true});