Home > Back-end >  Use other aggregate operators before search
Use other aggregate operators before search

Time:12-18

I've been exploring Atlas search and using its index to do a search on the data but before using the "$search" operator in the pipeline I want to narrow down the data by using a filter before that. But MongoDB doesn't allow that. Is there any way in which I can use a $match or any other operator before using $search to narrow down the data and improve performance

CodePudding user response:

So the answer is no, as specified in the docs:

$search must be the first stage of any pipeline it appears in

The reason for this as $search has to use the "special" text index atlas search builds, once you've loaded results into memory it cannot be used anymore.

Unfortunately there is no work around or "hack" you can use, I recommend considering why you need such usage, as it sounds a bit of an anti pattern.

  • Related