How is possible to rename a field in multiples documents in a MongoDB? I have a collections with elements like this, and I want the rename the field "name" by "userName" in all the collection
{
"name" : "luisPerez",
"address" : "Gaiman",
"addressFmt" : "Gaiman, Chubut Province, Argentina",
"loc" : {
"type" : "Point",
"coordinates" : [ -65.4920111, -43.2895976 ]
},
}
Update Multiple Fields of a Single Document. We can use $set and $inc operators to update any field in MongoDB. The $set operator will set the newly specified value while the $inc operator will increase the value by a specified value.
You may use rename operator to rename your fields
db.coll.update({}, {$rename:{"name":"userName"}}, false, true)
;
false : upsert:false
true : multi:true
Posible duplicity with:
How can I rename a field for all documents in MongoDB?
Posible use $rename
db.collection({}, {$rename:{"name":"userName"}}, false, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With