I have some data stored in my MongoDB
. The "tags" fields is actually an array of Strings
, but we have to update our model to store more data with those tags
Current model document
{
"id" : "59e4aefd74f12800019ba565",
"title" : "This is a title",
"tags" : [
"59b02e6f6b28ce0001f8c0a8",
"59b031886b28ce0001f8c0af",
"59ba8c1a5047570001a3c078"
]
}
Desired model after update
{
"id" : "59e4aefd74f12800019ba565",
"title" : "This is a title",
"tags" : [
{
"id" : "5a82ff1d889a15000103b115",
"internalName" : "Día Mundial de la Television"
},
{
"id" : "59ba8c1a5047570001a3c078",
"internalName" : "menu"
},
{
"id" : "5a26ac73d0fc2e00017f286e",
"internalName" : "oid_asdf_asd"
}
],
}
Now tags is a embedded object (forget about internalName field). How can I update the tag field without losing those data? I've tried with $rename, but it doesn't work well with arrays
db.test.update({}, {$rename: {'tags': 'tags2.id'}})