@@ -85,25 +85,52 @@ const users = await app.find('users', query);
8585
8686### Migration from Legacy Code
8787
88- If you have existing code using ` _id ` , you should migrate to using ` id ` for consistency:
88+ If you have existing code using ` _id ` , you have two options:
89+
90+ 1 . ** Recommended: Migrate to ` id ` ** for consistency across drivers:
8991
9092** Before (Legacy):**
9193``` typescript
9294// ❌ Old way - inconsistent with SQL drivers
9395const query = {
94- filters: [[' _id' , ' =' , ' 507f1f77bcf86cd799439011' ]]
96+ filters: [[' _id' , ' =' , ' 507f1f77bcf86cd799439011' ]],
97+ sort: [[' _id' , ' desc' ]],
98+ fields: [' _id' , ' name' ]
9599};
96100```
97101
98102** After (Recommended):**
99103``` typescript
100104// ✅ New way - consistent across all drivers
101105const query = {
102- filters: [[' id' , ' =' , ' 507f1f77bcf86cd799439011' ]]
106+ filters: [[' id' , ' =' , ' 507f1f77bcf86cd799439011' ]],
107+ sort: [[' id' , ' desc' ]],
108+ fields: [' id' , ' name' ]
103109};
104110```
105111
106- ** Note:** The MongoDB driver still accepts ` _id ` in filters for backward compatibility, but using ` id ` is strongly recommended for new code.
112+ 2 . ** Backward Compatible Mode:** Continue using ` _id ` in queries (results still return ` id ` )
113+
114+ The MongoDB driver ** fully supports ` _id ` in filters, sorting, and field projections** for backward compatibility:
115+
116+ ``` typescript
117+ // ✅ This works - backward compatible
118+ const query = {
119+ filters: [[' _id' , ' =' , ' 507f1f77bcf86cd799439011' ]],
120+ sort: [[' _id' , ' desc' ]],
121+ fields: [' _id' , ' name' ]
122+ };
123+ const users = await app .find (' users' , query );
124+
125+ // Results ALWAYS use 'id' regardless of query field name
126+ console .log (users [0 ].id ); // '507f1f77bcf86cd799439011'
127+ console .log (users [0 ]._id ); // undefined
128+ ```
129+
130+ ** Key Points:**
131+ - Queries accept both ` id ` and ` _id ` (automatically mapped to MongoDB's ` _id ` )
132+ - Results always return ` id ` field (never ` _id ` )
133+ - Using ` id ` is recommended for database portability
107134
108135## ID Generation
109136
0 commit comments