$match: Filtering documents

@3:05 a key thing to remember is “A $match stage may contain a $text query operator, but it must be the first stage in a pipeline”. What does “it” refer to - the match stage, or the query operator? If “it” refers to the stage, then what does the second bullet point “$match should come early in an aggregation pipeline” mean - because in my opinion, first is early.

What I understood, is $text must be in the first $match stage. If the $match does not contains a $text query it does not have to be the first stage, but it should be early in the pipeline. The $match stage filters the number of documents for later stages so it is better the filter out documents sooner than later.

I think your answer is sound. The word “must” is strong. I wonder if an error is thrown if found after the first $match or if it quietly fails.

I will try it when I have time and I’ll share the result.


It will raise an error like this one:

$match with $text is only allowed as the first pipeline stage

José Carlos