I have a Project collection that stores versions keyed by the version number, and each version has a config which has an array of packages.
A document looks like this:
{
"_id" : 12345,
"versions" : {
"1" : {
"status" : "OUTDATED",
"config" : {
"pkgs" : [
{ "id" : 1, "name" : "pkgX" },
{ "id" : 2, "name" : "pkgY" }
]
}
},
"2" : {
"status" : "LIVE",
"config" : {
"pkgs" : [
{ "id" : 1, "name" : "pkgZ" }
]
}
}
}
}
If it helps, in Java this is mapped as follows:
class Project {
Map<Integer, Version> versions;
class Version {
Config config;
class Config {
List<Pkg> pkgs
class Pkg {
int id;
I need to add a new sequence
property to each package, setting its value to the value of the id
.
Example: the item { "id" : 2, "name" : "pkgY" }
should become { "id" : 2, "sequence" : 2, "name" : "pkgY" }
In addition, my update should not break when the versions
property of the root document does not exist and when the pkgs
property of the config does not exist.
Thanks community in advance.