Unify primary key field as id across MongoDB and SQL drivers#27
Merged
Unify primary key field as id across MongoDB and SQL drivers#27
id across MongoDB and SQL drivers#27Conversation
…ally Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Contributor
|
@copilot 继续 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR unifies ID field handling across MongoDB and SQL drivers by standardizing on the id field name at the API level. The MongoDB driver now automatically maps between id (API) and _id (database) internally, eliminating the need for users to remember driver-specific field names.
Changes:
- Implemented automatic
id↔_idmapping in MongoDB driver for all operations (create, find, update, filters, sorting, projection) - Added comprehensive test coverage for the new ID mapping functionality
- Created detailed documentation including migration guide, driver-specific docs, and API reference updates
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/drivers/mongo/src/index.ts | Implements ID field mapping logic with helper methods and updates all CRUD operations to use unified id field |
| packages/drivers/mongo/test/index.test.ts | Adds test cases covering ID mapping in filters, sorting, projection, create, and find operations |
| docs/guide/migration-id-field.md | Provides comprehensive migration guide for transitioning from _id to id |
| docs/guide/drivers/mongo.md | Documents unified ID field approach with examples for MongoDB driver |
| docs/guide/drivers/sql.md | Documents unified ID field usage for SQL driver with backward compatibility notes |
| docs/guide/drivers/index.md | Updates main drivers documentation to explain unified ID field concept |
| docs/api/README.md | Updates API reference with unified ID field examples |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
|
@copilot 对 mongodb能否使用兼容模式,如果保存的查询只传入了_id 也能识别 |
Copilot
AI
changed the title
[WIP] Update API to unify _id and id usage across MongoDB and SQL
Unify primary key field as Jan 12, 2026
id across MongoDB and SQL drivers
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot stopped work on behalf of
hotlong due to an error
January 12, 2026 12:50
Contributor
|
@copilot 继续 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
hotlong
approved these changes
Jan 12, 2026
Copilot stopped work on behalf of
hotlong due to an error
January 12, 2026 13:49
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.
Plan: Unify ID Field Handling Across Drivers ✅
Problem
MongoDB uses
_idwhile SQL usesid, creating inconsistent API. Users need to know which driver they're using to reference the correct field.Solution
Standardize API to always use
id, with internal mapping in MongoDB driver.Changes Checklist
id(API) and_id(database)idto_idin create operations_idtoidin read operations (find, findOne)idto_idin filter queriesidto_idin sorting and field projection_idto_idfor full backward compatibility ✅idLatest Enhancement
Full Backward Compatibility for
_id:idAND_idin filters, sorting, and field projections_idwork without modificationidfor consistencyUser Request Addressed: "对 mongodb能否使用兼容模式,如果保存的查询只传入了_id 也能识别"
(Translation: "Can MongoDB use a compatibility mode? If the saved query only passes in _id, can it also be recognized?")
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.