I am trying to update the nested document
Document{{_id=59837be4324fb01040068109, idKey=2323, objects=[Document{{24889=Document{{key1=val1, key2=val2}}}}]}}
the json form looks like this
{
"_id": "59837be4324fb01040068109",
"idKey": 2323,
"objects": [{
"24889": {
"key1": "val1",
"key2": "val2"
}
}]
}
i tried to update as
String innerKey="24889";
mongoCollection.updateOne(eq("idKey", 2323),new Document("$set", new Document("objects."+innerKey+".key2", "val3")));
but then if i do
Document updatedDoc = mongoCollection.find(eq("idKey", 2323)).first();
i get
Document{{_id=59837be4324fb01040068109, idKey=2323, objects=[Document{{24889=Document{{key1=val1, key2=val2}}}}, null, null, null, null, null, null, null, ...
why did the object not get updated? and why do i have the nulls?