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: Azure Cosmos DB für MongoDB (Version 3.6): unterstützte Funktionen und Syntax | Microsoft Learn. How could this be achieved with these limitations in mind?
You can also answer this question on Stack Overflow: How to rename a field inside an array with database commands of Azure Cosmos DB's API for MongoDB (3.6 version)? - Stack Overflow