mongoDB快捷筛选相关优化#3327
Conversation
# Conflicts: # apps/desktop/src/components/document/DocumentBrowser.vue # package.json
# Conflicts: # 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
left a comment
There was a problem hiding this comment.
request changes: 目前有三个 MongoDB 正确性问题需要先处理。
-
DocumentBrowser.vue在文档结果改为 Extended JSON 后仍用String(id)传递_id。ObjectId 会变成[object Object]或序列化 JSON,而后端只识别裸 24 位 hex,导致编辑和删除静默匹配 0 个文档。请统一提取$oid,或让后端直接解析 Extended JSON_id,并补充 ObjectId 编辑/删除测试。 -
mongo_driver.rs使用 relaxed Extended JSON 返回文档,会把超出 JavaScript safe integer 范围的 BSON Int64 输出成普通 JSON number,前端解析时已经发生精度丢失。请使用 canonical Extended JSON,或确保大 Int64 始终以$numberLong返回,并补充真实 round-trip 测试。 -
documentStoreProvider.ts会把$oid、$date、$numberLong等 wrapper 当作真实嵌套字段,快捷筛选会出现无效路径。请将已识别的 BSON wrapper 作为 scalar leaf。
另外 cargo fmt --check 当前失败,需要格式化后再更新。
# 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
t8y2
left a comment
There was a problem hiding this comment.
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
t8y2
left a comment
There was a problem hiding this comment.
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.
# Conflicts: # crates/dbx-core/src/db/mongo_driver.rs
t8y2
left a comment
There was a problem hiding this comment.
当前 head 仍有一个会生成无效 MongoDB 快速筛选路径的问题需要修复。
apps/desktop/src/lib/app/documentStoreProvider.ts:182在遍历数组元素时,只判断元素是不是普通对象,没有排除 BSON Extended JSON wrapper;同时arrayContainsPlainRecord也会把{ $date: ... }、{ $oid: ... }、{ $numberLong: ... }这类 wrapper 当成数组对象。因此包含 BSON Date/ObjectId/Int64 的数组会被标记为array-object,并暴露items.$date、items.$oid等可选字段。这些键只是 Extended JSON 序列化形式,不是真实 MongoDB 字段路径,生成的 quick filter 无法匹配原 BSON 值。请在数组类型判定和递归收集两处统一排除 Extended JSON wrapper,并覆盖直接数组、嵌套数组以及 wrapper 与真实文档混合的回归测试。
另外当前分支状态为 CONFLICTING/DIRTY,请在修复后同步解决与 main 的冲突。
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
# Conflicts: # package.json
t8y2
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the contribution! Merged in 681da22, will be released in the next version. |
变更说明
mongoDB快捷筛选,行详情的嵌套显示与json格式化显示及搜索。
优化了之前pr提的一些问题。
文档模式下编辑数组可以选择要编辑的类型,补充了原生json的编辑形式,给文档模式加了ctrl+f。
之前的pr手滑给干掉了T_T,现在重新提一下:#3009
变更类型
涉及前端
验证
make check通过make cargo-check-fast通过关联 Issue