Skip to content

mongoDB快捷筛选相关优化#3327

Merged
t8y2 merged 42 commits into
t8y2:mainfrom
ColdSand803:main
Jul 17, 2026
Merged

mongoDB快捷筛选相关优化#3327
t8y2 merged 42 commits into
t8y2:mainfrom
ColdSand803:main

Conversation

@ColdSand803

Copy link
Copy Markdown
Contributor

变更说明

mongoDB快捷筛选,行详情的嵌套显示与json格式化显示及搜索。
优化了之前pr提的一些问题。
文档模式下编辑数组可以选择要编辑的类型,补充了原生json的编辑形式,给文档模式加了ctrl+f。

之前的pr手滑给干掉了T_T,现在重新提一下:#3009

变更类型

  • 新功能
  • Bug 修复
  • 性能优化
  • 代码重构
  • 文档更新
  • CI / 构建

涉及前端

  • 本 PR 涉及前端改动,已附截图/录屏(见下方)
image image image image

验证

  • make check 通过
  • make cargo-check-fast 通过
  • 相关测试通过
  • [ ]

关联 Issue

co1dsand and others added 28 commits July 6, 2026 18:26
# Conflicts:
#	apps/desktop/src/components/document/DocumentBrowser.vue
#	package.json
# Conflicts:
#	package.json
# Conflicts:
#	apps/desktop/src/components/layout/ContentArea.vue
#	apps/desktop/src/lib/app/documentStoreProvider.ts
#	apps/desktop/src/lib/dataGrid/dataGridDetail.ts
#	packages/app-tests/dataGridDetail.test.ts
#	packages/app-tests/documentStoreProvider.test.ts
# Conflicts:
#	apps/desktop/src/components/document/DocumentBrowser.vue

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes: 目前有三个 MongoDB 正确性问题需要先处理。

  1. DocumentBrowser.vue 在文档结果改为 Extended JSON 后仍用 String(id) 传递 _id。ObjectId 会变成 [object Object] 或序列化 JSON,而后端只识别裸 24 位 hex,导致编辑和删除静默匹配 0 个文档。请统一提取 $oid,或让后端直接解析 Extended JSON _id,并补充 ObjectId 编辑/删除测试。

  2. mongo_driver.rs 使用 relaxed Extended JSON 返回文档,会把超出 JavaScript safe integer 范围的 BSON Int64 输出成普通 JSON number,前端解析时已经发生精度丢失。请使用 canonical Extended JSON,或确保大 Int64 始终以 $numberLong 返回,并补充真实 round-trip 测试。

  3. documentStoreProvider.ts 会把 $oid$date$numberLong 等 wrapper 当作真实嵌套字段,快捷筛选会出现无效路径。请将已识别的 BSON wrapper 作为 scalar leaf。

另外 cargo fmt --check 当前失败,需要格式化后再更新。

ColdSand803 and others added 4 commits July 14, 2026 11:21
# Conflicts:
#	apps/desktop/src/components/document/DocumentBrowser.vue
#	apps/desktop/src/lib/app/documentStoreProvider.ts
#	apps/desktop/src/lib/mongo/mongoDocumentValues.ts
#	crates/dbx-core/src/db/mongo_driver.rs
#	packages/app-tests/mongoDocumentValues.test.ts
@ColdSand803
ColdSand803 requested a review from t8y2 July 14, 2026 03:53

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes: 前一轮的 ObjectId、Int64 精度和 Extended JSON wrapper 字段路径问题,在当前 head 上基本都有对应修复;不过 Int64 的处理方式引入了一个影响范围更大的回归。

mongo_driver.rs 现在对所有文档使用 canonical Extended JSON。canonical 不只包装超出 JavaScript safe integer 的 Int64,还会把普通 Int32、Double、Date 等转换成 $numberInt$numberDouble$date wrapper;DocumentBrowser.vue 随后会直接将这些对象 JSON.stringify,所以普通数值和日期字段也会在表格中显示成 Extended JSON 对象,并可能影响编辑后的 BSON 类型保持。

请改为只对不安全 Int64 保留 $numberLong,或者在前端增加统一的 typed-value 展示层,保证普通数值和日期仍按原来的可读形式展示,同时过滤和编辑继续使用原始 BSON 类型。还需要补充 Int32、Double、Date 以及 unsafe Int64 的展示、筛选和编辑回归测试。

# Conflicts:
#	apps/desktop/src/components/document/DocumentBrowser.vue
#	apps/desktop/src/lib/mongo/mongoDocumentValues.ts
#	crates/dbx-core/src/db/mongo_driver.rs
#	packages/app-tests/mongoDocumentValues.test.ts
@ColdSand803
ColdSand803 requested a review from t8y2 July 14, 2026 07:52

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: full-document editing can still silently change BSON Date values into strings.

The displayed document mixes Extended JSON wrappers such as $oid with ISODate("...") strings. Because the save path switches the entire document to Extended JSON decoding as soon as any wrapper exists, a normal document containing an ObjectId _id will decode ISODate(...) as a plain string rather than Bson::DateTime. Editing an unrelated field and saving can therefore corrupt the original BSON type.

Please preserve types per value instead of selecting one decoding strategy for the whole document, and add a round-trip test containing ObjectId, Date, and an unsafe Int64 while editing an unrelated field.

@ColdSand803
ColdSand803 requested a review from t8y2 July 15, 2026 06:57

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前 head 仍有一个会生成无效 MongoDB 快速筛选路径的问题需要修复。

  1. apps/desktop/src/lib/app/documentStoreProvider.ts:182 在遍历数组元素时,只判断元素是不是普通对象,没有排除 BSON Extended JSON wrapper;同时 arrayContainsPlainRecord 也会把 { $date: ... }{ $oid: ... }{ $numberLong: ... } 这类 wrapper 当成数组对象。因此包含 BSON Date/ObjectId/Int64 的数组会被标记为 array-object,并暴露 items.$dateitems.$oid 等可选字段。这些键只是 Extended JSON 序列化形式,不是真实 MongoDB 字段路径,生成的 quick filter 无法匹配原 BSON 值。请在数组类型判定和递归收集两处统一排除 Extended JSON wrapper,并覆盖直接数组、嵌套数组以及 wrapper 与真实文档混合的回归测试。

另外当前分支状态为 CONFLICTING/DIRTY,请在修复后同步解决与 main 的冲突。

ColdSand803 and others added 4 commits July 17, 2026 14:23
Array elements that are BSON Extended JSON wrappers ({ $date }, { $oid },
{ $numberLong }, etc.) were treated as plain records, so arrays containing
BSON Date/ObjectId/Int64 values were marked as array-object and exposed
invalid quick filter paths like items.$date and items.$oid. Those keys are
only Extended JSON serialization form, not real MongoDB field paths, so the
generated quick filters could not match the original BSON values.

Exclude Extended JSON wrappers in both the array kind detection
(arrayContainsPlainRecord) and the recursive collection
(collectArrayDocumentFieldPathNodes), and cover direct arrays, nested
arrays, and wrapper/document mixed arrays with regression tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts:
#	apps/desktop/src/components/document/DocumentBrowser.vue
#	apps/desktop/src/components/grid/DataGrid.vue
#	apps/desktop/src/i18n/locales/en.ts
#	apps/desktop/src/i18n/locales/zh-CN.ts
#	apps/desktop/src/lib/app/documentStoreProvider.ts
#	apps/desktop/src/stores/queryStore.ts
#	packages/app-tests/documentStoreProvider.test.ts
#	packages/app-tests/mongoDocumentValues.test.ts

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer patch applied in 1c15d2c.

MongoDB quick filters lost Date/ObjectId types when the sampled field was a scalar array, and literal Contains input was passed directly to $regex, so metacharacters changed query semantics or produced invalid patterns.

The patch infers BSON types only from homogeneous non-null scalar wrapper arrays, leaves mixed arrays untyped, and escapes regex metacharacters for literal Contains/Does not contain behavior. Focused regression coverage was added for ObjectId/Date arrays, mixed arrays, and regex metacharacters.

Validation:

  • focused Vitest: 38/38 passed
  • touched-file oxfmt and oxlint
  • MongoDB 4.4 live verification for typed array equality and escaped literal matching
  • git diff --check

The full local typecheck remains blocked by the PR worktree's existing missing @dbx-app/mongo-shell package and related pre-existing errors; GitHub CI is required before merge.

@t8y2
t8y2 merged commit 681da22 into t8y2:main Jul 17, 2026
8 checks passed
@t8y2

t8y2 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 681da22, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants