Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Plan: Unify ID Field Handling Across Drivers ✅

Problem

MongoDB uses _id while SQL uses id, 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

  • Update MongoDB driver to map between id (API) and _id (database)
    • Map id to _id in create operations
    • Map _id to id in read operations (find, findOne)
    • Map id to _id in filter queries
    • Map id to _id in sorting and field projection
    • NEW: Map _id to _id for full backward compatibility
    • Update tests for MongoDB driver
    • All MongoDB driver tests pass (12 tests) ✅
    • Fixed filter mapping bug found in code review ✅
  • Ensure SQL driver consistently uses id
    • Verified existing implementation
    • All SQL driver tests pass ✅
  • Add comprehensive documentation
    • Update MongoDB driver documentation to explain unified ID approach
    • NEW: Enhanced docs to explain full backward compatibility
    • Update SQL driver documentation to explain unified ID approach
    • Update main drivers index documentation
    • Create migration guide for existing users
    • NEW: Updated migration guide with backward compatibility details
    • Update API reference documentation
  • Run all tests to ensure no breaking changes - 67 tests pass (excluding unrelated server test failures) ✅
  • Request code review - Completed and addressed feedback ✅
  • Run security scan - No vulnerabilities found ✅

Latest Enhancement

Full Backward Compatibility for _id:

  • MongoDB driver now accepts both id AND _id in filters, sorting, and field projections
  • Legacy queries using _id work without modification
  • Results always return id for consistency
  • Added 3 new tests for backward compatibility (total: 12 MongoDB tests)
  • Enhanced documentation to clearly explain backward compatibility mode

User 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

如何解决】 mongodb 使用 _id 而 sql 使用 id的问题,我希望统一API,而且目前缺少相关的规范说明文档


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 12, 2026 11:59
…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>
@hotlong
Copy link
Contributor

hotlong commented Jan 12, 2026

@copilot 继续

Copy link
Contributor

Copilot AI left a 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_id mapping 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

hotlong and others added 3 commits January 12, 2026 20:30
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>
@hotlong
Copy link
Contributor

hotlong commented Jan 12, 2026

@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 id across MongoDB and SQL drivers Jan 12, 2026
Copilot AI requested a review from hotlong January 12, 2026 12:33
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@hotlong
Copy link
Contributor

hotlong commented Jan 12, 2026

@copilot 继续

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@hotlong hotlong marked this pull request as ready for review January 12, 2026 13:48
@hotlong hotlong merged commit 821e1b6 into main Jan 12, 2026
2 checks passed
Copilot AI requested a review from hotlong January 12, 2026 13:49
Copilot stopped work on behalf of hotlong due to an error January 12, 2026 13:49
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