fix(mongodb): preserve null fields in grid edits

Closes #5773
This commit is contained in:
t8y2 committed 2026-08-10 16:13:49 +08:00
1 parent 5fe3b5b435
commit 20ddf2eca5
2 files changed
+21

No files matched your search

+20
View File
@@ -322,6 +322,8 @@ test("formats other extended JSON values through EJSON.deserialize", () => {
});
test("keeps normal Mongo values readable and unsafe Int64 editable", () => {
assert.equal(mongoDocumentDisplayValue(null), "NULL");
assert.equal(mongoDocumentDisplayValue(undefined), undefined);
assert.equal(mongoDocumentDisplayValue(42), 42);
assert.equal(mongoDocumentDisplayValue(3.5), 3.5);
assert.equal(mongoDocumentDisplayValue('ISODate("2026-07-14T00:00:00Z")'), 'ISODate("2026-07-14T00:00:00Z")');
@@ -340,3 +342,21 @@ test("builds edits for Int32, Double, Date, and unsafe Int64", () => {
$set: { int32: 42, double: 3.5, createdAt: { $date: "2026-07-14T00:00:00Z" }, unsafe: { $numberLong: "9007199254740993" } },
});
});
test("keeps explicit Mongo null fields distinct from missing fields during grid edits", () => {
const columns = ["_id", "nullable", "missing"];
assert.deepEqual(buildMongoUpdateDocument(new Map([[1, "NULL"]]), columns, { _id: "1", nullable: null }), {
$set: { nullable: null },
});
assert.deepEqual(buildMongoUpdateDocument(new Map([[1, "NULL"]]), columns, { _id: "1", nullable: "NULL" }), {
$set: { nullable: "NULL" },
});
assert.deepEqual(buildMongoUpdateDocument(new Map([[2, null]]), columns, { _id: "1", nullable: null }), {
$unset: { missing: "" },
});
assert.deepEqual(applyMongoGridChangesToDocument({ _id: "1", nullable: null }, new Map([[1, "NULL"]]), columns), {
_id: "1",
nullable: null,
});
});