Skip to content

Commit

Permalink
document remove fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Sep 25, 2024
1 parent 57dbf3c commit 003f847
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ private void deepRemove(String[] splits) {
// if there are more splits, then this is an embedded document
// so remove the element at the next level
((NitriteDocument) item).deepRemove(Arrays.copyOfRange(splits, 2, splits.length));
if (((NitriteDocument) item).size() == 0) {
// if the next level document is an empty one
// remove the element at the current level
list.remove(index);
this.put(key, list);
}
} else {
// if there are no more splits, then this is a primitive value
// so remove the element at the next level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public void testRemoveFromArray() {

assertEquals(((List<?>) doc.get("objArray")).size(), 2);
doc.remove("objArray:0:value");
assertEquals(((List<?>) doc.get("objArray")).size(), 2);
assertEquals(((Document) doc.get("objArray:0")).size(), 0);
assertEquals(((List<?>) doc.get("objArray")).size(), 1);
assertEquals(((Document) doc.get("objArray:0")).size(), 1);
}

@Test
Expand Down

0 comments on commit 003f847

Please sign in to comment.