25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(mongodb): preserve null fields in grid edits
t8y220ddf2eca51c
diff --git a/apps/desktop/src/lib/mongo/mongoDocumentValues.ts b/apps/desktop/src/lib/mongo/mongoDocumentValues.tsindex f58df51369..2fdc818110 100644--- a/apps/desktop/src/lib/mongo/mongoDocumentValues.ts+++ b/apps/desktop/src/lib/mongo/mongoDocumentValues.ts@@ -74,6 +74,7 @@ export function parseMongoDocumentInputValue(raw: MongoInputValue): unknown {}export function mongoDocumentDisplayValue(value: unknown): unknown {+ if (value === null) return "NULL";if (value && typeof value === "object" && !Array.isArray(value)) {const object = value as Record<string, unknown>;if (Object.keys(object).length === 1 && typeof object.$numberLong === "string") return `NumberLong(${JSON.stringify(object.$numberLong)})`;diff --git a/packages/app-tests/mongoDocumentValues.test.ts b/packages/app-tests/mongoDocumentValues.test.tsindex 5b33b91f12..ff0842f5d1 100644--- a/packages/app-tests/mongoDocumentValues.test.ts+++ b/packages/app-tests/mongoDocumentValues.test.ts@@ -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,+ });+});