简体   繁体   English

如何更新mongodb中字段的值?

[英]How to update the value of the field in mongodb?

I have a document as follows in mongodb:我在mongodb中有如下文档:

{
 "_id":"563f480fb5c2187503eefc1a",
 "ownerBy":"56335521f2f4a3150349d78d",
 "data":   {
   "username1":"76561198060520554",
   "username2":"76561198060520554",
   "username3":"76561198060520554",
   "username4":"76561198060520554",
   "username5":"76561198060520554"
  }, 
 "__v":0
}

The client wants to update the value of username1 to the following newValue :客户端希望将username1的值更新为以下newValue

{ newValue: 'as76561198060520554',
  id: 'username1',
  column: 'selectable' 
}

How can I find the field _id and replace that with newValue ?如何找到字段_id并将其替换为newValue

Given the little information we have, this could possibly be what you're looking for!鉴于我们掌握的信息很少,这可能就是您要找的!

Collection would be the name of your collection!收藏将是您收藏的名称!

Collection.update({
"_id":"563f480fb5c2187503eefc1a"
},
{$rename: {"_id" : "newValue"}},
{$set: { 
newValue: 'as76561198060520554',

id: 'username1',
column: 'selectable' 
}},
{"upsert": true});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM