I want to filter documents by docname first (reducing dataset from ~100K to ~500 docs), then perform text search only on that filtered subset for better performance.
My Questions:
Is there a way to force MongoDB to filter first, then apply text search to that subset? Are there any aggregation pipeline techniques that could achieve filter-first behavior?
My Setup:
Collection: docs
Documents have fields: solution_id, docname, searchable (text content)
Current indexes: { searchable: “text” } (global text index)
Current Behavior:
Doc.where(docname: "TEXT SUMMARY").where( "$text: { $search: "floor plan details" }
)
The execution plan shows:
TEXT_MATCH stage (searches entire text index first)
FETCH stage with docname filter (filters results after text search)