I am using php and MongoDB, the opensource library that i am using makes an auto-generated code to make calls to mongodb. it is sort of an ODM layer.
Now when i am using embedded documents, in the parent document, i have to update the set of embedded documents, the Library makes a call using $unset
, which as per Documentation sets the value at index to null and does not remove it.
thus now when i want to replace the embedded document set, i have to first remove($unset) the existing set, and then add new leaving me with the result like this:
Original:
{
"parentDocument": {
"parent_id": "1",
"embeddedDocument": {
"0": {
"childValue": "0"
},
"1": {
"childValue": "1"
},
"2": {
"childValue": "2"
}
}
}
}
Updated:
{
"parentDocument": {
"parent_id": "1",
"embeddedDocument": {
"0": null,
"1": null,
"2": {
"childValue": "2"
}
}
}
}
How can i clean this data from the db..?? I have tried many forums, didnt find any valid solution for the same. I need to clean this complete data. Thanks