I want to change the key of a field from name
to title
with database commands and NOT the shell. Below is a minified version of my collection for reference. I literally only want to change every key called name
into title
.
[{
identifier: "x",
versions: [
{
name: "test_name"
version: "x.x.x"
},
{
name: "test_name"
version: "x.x.x"
},
]
},
{
identifier: "y",
versions: [
{
name: "test_name2"
version: "x.x.x"
},
{
name: "test_name2"
version: "x.x.x"
},
]
}, ... ]
This query basically does exactly what I need, but it, unfortunately, isn’t supported by the newest CosmosDB MongoDB-API:
db.runCommand({
update: 'apps',
updates: [
{
q: { "versions.name": { $exists: true } },
u: [
{
$set: {
versions: {
$map: {
input: "$versions",
in: {
$mergeObjects: [
"$$this",
{ "title": "$$this.name" }
]
}
}
}
}
},
{ $unset: "versions.name" }
],
multi: true
}
]
})
You can find what is supported here: https://docs.microsoft.com/de-de/azure/cosmos-db/mongodb-feature-support-36. How could this be achieved with these limitations in mind?
You can also answer this question on Stack Overflow: https://stackoverflow.com/questions/66348675/how-to-rename-a-field-inside-an-array-with-database-commands-of-azure-cosmos-db