Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save houstondapaz/abf5d52a8dab62df8797e38940dd9273 to your computer and use it in GitHub Desktop.
Save houstondapaz/abf5d52a8dab62df8797e38940dd9273 to your computer and use it in GitHub Desktop.
Update mongodb nested object arrays
// schema
// {
// "EnvironmentSettings": [
// {
// "ProductName": "Product",
// "Settings": [
// {
// "Key": "key1",
// "Value": "value1"
// }
// ]
// }
// ]
// }
db["setup"].update(
{
EnvironmentSettings: {
$elemMatch: {
ProductName: "Product"
}
}
},
{
$set: {
"EnvironmentSettings.$[].Settings.$[setting].Value": "value2"
}
},
{
arrayFilters: [
{
"setting.Key": "key1"
}
]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment