I have some documents of the form:
{
"root": {
"field1a": {
"field2a": {
"value": 1
},
"field2b": {
"value": 1
}
},
"field1b": {
"field2a": {
"value": 2
},
"field2b": {
"value": 2
}
}
},
}
Various modifications are being done with the subdoc API. However, the delete creates an issue. I need to remove elements at the “field2” layer. However, when a given node at the “field1” layer has no more children left, it will be left hanging:
{
"root": {
"field1a": {}, // field1a here is empty
"field1b": {
"field2a": {
"value": 2
}
}
},
}
Since some logic may rely on the existence of certain keys, I need to clean up these empty path stubs. I can obviously iterate through and check this, and then delete any childless nodes. However I’m wondering if there is a cleaner way to do this. I am implementing a bunch of such deletes at different layers, and it seems a little bit cumbersome to iterate through and check whether everything has children.