diff --git a/packages/mongodb/src/adapter.ts b/packages/mongodb/src/adapter.ts index 9a1695b4d..f25c0ceeb 100644 --- a/packages/mongodb/src/adapter.ts +++ b/packages/mongodb/src/adapter.ts @@ -148,10 +148,6 @@ export class MongoDbAdapter< pipeline.push({ $sort: filters.$sort }) } - if (filters.$select !== undefined) { - pipeline.push({ $project: this.getProjection(filters.$select) }) - } - if (filters.$skip !== undefined) { pipeline.push({ $skip: filters.$skip }) } @@ -160,6 +156,10 @@ export class MongoDbAdapter< pipeline.push({ $limit: filters.$limit }) } + if (filters.$select !== undefined) { + pipeline.push({ $project: this.getProjection(filters.$select) }) + } + return pipeline } @@ -167,6 +167,7 @@ export class MongoDbAdapter< if (!select) { return undefined } + if (Array.isArray(select)) { if (!select.includes(this.id)) { select = [this.id, ...select]