Answer the question
In order to leave comments, you need to log in
How to update field value in mongo?
This is how the db schema looks like:
{"_id":"563f480fb5c2187503eefc1a","ownerBy":"56335521f2f4a3150349d78d","data":{"username1":"76561198060520554","username2":"76561198060520554","username3":"76561198060520554","username4":"76561198060520554","username5":"76561198060520554"},"__v":0}
{ newValue: 'as76561198060520554',
id: 'username1',
column: 'selectable' }
Answer the question
In order to leave comments, you need to log in
Something like this:
db.collection.find({ "data.username1" : {$exists: true}}).forEach( function(myDoc) { db.collection.update({_id: myDoc._id}, {$set : {"data.username1": myDoc.newValue}} )});
If I correctly understood the intricacies of your data.
db.collection.update({ 'data.username1': {$exists: true} }, { $set: { 'data.username1': newValue }}, true)
{
"_id":"563f480fb5c2187503eefc1a"
"ownerBy":"56335521f2f4a3150349d78d",
"data":{"username1":"76561198060520554","username2":"76561198060520554"...},
"__v":0,
userList: ['username1', 'username2', 'username3']
}
db.collection.ensureIndex({userList: 1})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question