Skip to content

Commit bb454d6

Browse files
Copilothotlong
andcommitted
fix: Update QueryAST tests and fix count/projection logic
- Fix count method to handle query objects - Fix field projection to exclude _id when not requested - Update tests to use mocks instead of MongoMemoryServer - All 70 tests passing Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a2733f0 commit bb454d6

File tree

3 files changed

+177
-76
lines changed

3 files changed

+177
-76
lines changed

packages/drivers/mongo/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ export class MongoDriver implements Driver {
284284
const dbField = (field === 'id' || field === '_id') ? '_id' : field;
285285
(findOptions.projection as any)[dbField] = 1;
286286
}
287+
// Explicitly exclude _id if 'id' is not in the requested fields
288+
const hasIdField = normalizedQuery.fields.some((f: string) => f === 'id' || f === '_id');
289+
if (!hasIdField) {
290+
(findOptions.projection as any)._id = 0;
291+
}
287292
}
288293

289294
const results = await collection.find(filter, findOptions).toArray();
@@ -344,7 +349,10 @@ export class MongoDriver implements Driver {
344349

345350
async count(objectName: string, filters: any, options?: any): Promise<number> {
346351
const collection = await this.getCollection(objectName);
347-
const filter = this.mapFilters(filters);
352+
// Normalize to support both filter arrays and full query objects
353+
const normalizedQuery = this.normalizeQuery(filters);
354+
const actualFilters = normalizedQuery.filters || filters;
355+
const filter = this.mapFilters(actualFilters);
348356
return await collection.countDocuments(filter);
349357
}
350358

0 commit comments

Comments
 (0)