Skip to content

Commit

Permalink
Rearrange pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
DaddyWarbucks committed Oct 10, 2024
1 parent e6595b8 commit e126577
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/mongodb/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand All @@ -160,13 +156,18 @@ export class MongoDbAdapter<
pipeline.push({ $limit: filters.$limit })
}

if (filters.$select !== undefined) {
pipeline.push({ $project: this.getProjection(filters.$select) })
}

return pipeline
}

getProjection(select?: string[] | { [key: string]: number }) {
if (!select) {
return undefined
}

if (Array.isArray(select)) {
if (!select.includes(this.id)) {
select = [this.id, ...select]
Expand Down

0 comments on commit e126577

Please # to comment.