Skip to content

Commit ca80241

Browse files
committed
document remove fixed
1 parent 2add961 commit ca80241

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/nitrite/lib/src/collection/document.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ class _NitriteDocument extends Document {
416416
// if there are more splits, then this is an embedded document
417417
// so remove the element at the next level
418418
item._deepRemove(remainingSplits.sublist(1));
419+
if (item.isEmpty) {
420+
// if the next level document is an empty one
421+
// remove the current level document also
422+
value.removeAt(index);
423+
_documentMap[key] = value;
424+
}
419425
} else {
420426
// if there are no more splits, then this is a primitive value
421427
// so remove the element at the next level

packages/nitrite/test/collection/document_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void main() {
228228

229229
expect(doc["objArray"].length, 2);
230230
doc.remove("objArray:0:value");
231-
expect(doc["objArray"].length, 2);
232-
expect(doc["objArray:0"].size, 0);
231+
expect(doc["objArray"].length, 1);
232+
expect(doc["objArray:0"].size, 1);
233233
});
234234

235235
test("Get Fields", () {

0 commit comments

Comments
 (0)