Skip to content

fix(Jobs): fix jobs fullfacet access with text#2736

Open
abdimo101 wants to merge 1 commit into
masterfrom
fix-jobs-fullfacet-text
Open

fix(Jobs): fix jobs fullfacet access with text#2736
abdimo101 wants to merge 1 commit into
masterfrom
fix-jobs-fullfacet-text

Conversation

@abdimo101
Copy link
Copy Markdown
Member

@abdimo101 abdimo101 commented May 18, 2026

Description

This PR places a check if the pipeline contains a text and merges access to the text match so MongoDB accepts the pipeline and access is still enforced.

Motivation

When searching in Jobs table, the fullfacet endpoint throws an error:

"{status: 400, message: "$match with $text is only allowed as the first pipeline stage"}
message
:
"$match with $text is only allowed as the first pipeline stage"
status
:
400"

Fixes

  • Bug fixed (#X)

Changes:

  • changes made

Tests included

  • Included for each change/fix?
  • Passing?

Documentation

  • swagger documentation updated (required for API changes)
  • official documentation updated

official documentation info

Summary by Sourcery

Bug Fixes:

  • Fix jobs fullfacet aggregation error when combining access filtering with $text search by correctly positioning and merging the $match stage.

@abdimo101 abdimo101 requested a review from a team as a code owner May 18, 2026 09:07
@abdimo101 abdimo101 requested review from Junjiequan and minottic May 18, 2026 09:08
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new logic assumes pipeline[0] always exists and is a $match stage when fields['text'] is set; consider adding a guard or explicit validation so you don't access firstStage.$match when the pipeline is empty or starts with a different stage.
  • Instead of checking if (fields['text']), it may be safer to check explicitly for the presence of a text search stage (or a specific field structure) in the pipeline, so that access control merging is only applied when the first stage is actually the $text $match you expect.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new logic assumes `pipeline[0]` always exists and is a `$match` stage when `fields['text']` is set; consider adding a guard or explicit validation so you don't access `firstStage.$match` when the pipeline is empty or starts with a different stage.
- Instead of checking `if (fields['text'])`, it may be safer to check explicitly for the presence of a text search stage (or a specific field structure) in the pipeline, so that access control merging is only applied when the first stage is actually the `$text` `$match` you expect.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant