fix(mongodb): 修复长整型筛选与 _id 更新失败#3296
Merged
Merged
Conversation
t8y2
requested changes
Jul 13, 2026
t8y2
left a comment
Owner
There was a problem hiding this comment.
request changes: 长整型 _id 的整体处理方向没问题,但 Legacy MongoDB Agent 还有一个兼容性问题。
MongoAgent.parseId 现在会把所有以 { 开头的 _id 都交给 Document.parse。这会导致合法的 String _id(例如 "{}" 或 "{\"tenant\":1}")在更新和删除时被重新解释成 BSON Document,从而匹配错误的文档或完全匹配不到。
这里只应解析明确支持的标量 Extended JSON ID wrapper,例如单字段的 {"$numberLong":"..."};其他 JSON-looking 值仍应按原始字符串处理。请补充上述 String _id 的回归测试。
另外当前分支与 main 存在冲突;rebase 时需要保留 main 上最近加入的 JSON-looking string value 类型保护。
zipg
force-pushed
the
codex/fix-mongodb-long-id-2527
branch
from
July 13, 2026 15:11
1977344 to
a925f62
Compare
Contributor
Author
|
已按评审意见处理,并已 rebase 到最新 main:
验证通过:
修复提交:a925f626 |
t8y2
approved these changes
Jul 14, 2026
Owner
|
Thanks for the contribution! Merged in 2a5e7ac, will be released in the next version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Issue #2527 在已发布修复后追加反馈:0.5.55 中,MongoDB 雪花 ID 仍存在三个相关问题:
NumberLong(...)查询无法执行;NumberLong(...)同样无法执行;Int64类型的_id在查询结果中编辑保存时,被当作字符串条件,导致更新匹配不到文档。原因
此前的修复会使用 Extended JSON
$numberLong保存长整型筛选精度,并在查询预览中显示为NumberLong(...),但链路仍有缺口:ObjectId和日期构造器,没有识别NumberLong,预览语句重新执行时会解析失败;$numberLong解码为 BSONInt64;Int64显示为字符串,同时丢失_id的原始 BSON 类型,保存时最终生成了字符串匹配条件。修改
NumberLong(...),统一转换为$numberLong;Int64;Int64类型的_id保留类型元数据,表格仍显示纯数字;_id,生成NumberLong("...")条件并精确更新;_id类型并按 Extended JSON ID 更新;Number舍入。实现保留了字符串
_id的原有语义:即使数据库中同时存在数字文本相同的 String_id和 Int64_id,更新 Int64 文档也不会误改字符串文档。验证
pnpm check:format、lint、typecheck、全量 2774 项测试通过;cargo test -p dbx-core db::mongo_driver::tests --lib:45 项通过;cargo fmt --all -- --check:通过;./gradlew :mongodb:test :mongodb:shadowJar:通过;$numberLong筛选命中 1 条;_id更新返回 1,回读值正确;_id文档未被修改;modified_count: 1,回读值正确。Refs #2527(修复该 Issue 的最新评论追加反馈)