Следующий код может помочь:
// Getting all documents from the collection
var data = db.collection.find({},{"_id":0}).toArray();
// Converting the data into JSON string
var string = JSON.stringify(data);
// Replacing all variations of assetid with Asset_ID
string = string.replace(/assetid/ig,"Asset_ID");
// Removing existing documents from collection
db.collection.remove({});
// Converting the string back to JSON array and inserting it into the DB
db.collection.insertMany(JSON.parse(string));
До:
{
"_id" : ObjectId("5d89e9ab0558a18dd9cfc03a"),
"Equipments" : [
{
"InnerEquipments" : {
"AssetId" : 678
},
"AssetID" : 456
}
],
"AssetID" : 123
}
После:
{
"_id" : ObjectId("5d89eea80558a18dd9cfc03b"),
"Equipments" : [
{
"InnerEquipments" : {
"Asset_ID" : 678
},
"Asset_ID" : 456
}
],
"Asset_ID" : 123
}