diff --git a/src/jobs/jobs.service.ts b/src/jobs/jobs.service.ts index 126e19245..317c884c6 100644 --- a/src/jobs/jobs.service.ts +++ b/src/jobs/jobs.service.ts @@ -195,9 +195,16 @@ export class JobsService { JobDocument, IJobFields >(this.jobModel, "id", fields, facets); - pipeline.unshift({ - $match: access, - }); + + const firstStage = pipeline[0] as { $match: Record }; + + if (fields["text"]) { + pipeline.splice(0, 1, { $match: { $and: [access, firstStage.$match] } }); + } else { + pipeline.unshift({ + $match: access, + }); + } return await this.jobModel.aggregate(pipeline).exec(); }