-
Notifications
You must be signed in to change notification settings - Fork 0
Unify primary key field as id across MongoDB and SQL drivers
#27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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>
|
@copilot 继续 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
|
@copilot 对 mongodb能否使用兼容模式,如果保存的查询只传入了_id 也能识别 |
id across MongoDB and SQL drivers
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
@copilot 继续 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
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.