Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Atlas Search
Created by Guest
Created on May 26, 2020

Allow $search to be a later stage in the aggregation pipeline

Currently $search is required to be the first stage in the aggregation pipeline. It would be more intuitive if we could use after other operators, such as $match.
  • Guest
    Nov 20, 2023
    It would also be great (even better :) ) to be able to call $search after $unwind, because it is currently impossible to score individual embeddedDocuments.
  • Guest
    Oct 25, 2021
    This would be great if the $search stage following a $match can be made as performant as when it is the first stage. My suspicion is that some of the id lookup will be required after the $match stage while handing off the the $search stage, and that might not be as performant.
  • Guest
    Aug 17, 2021
    Could this include executing the search separately, then merging the results with the previous stage(s)?
  • Guest
    Oct 27, 2020
    Tyler, multi-tenancy can be accomplished easily with the filter clause within the compound operator for search and others. I'm attaching an example query with the same message that I am posting here. Of course, the comment is not valid JSON so you would need to run the query if you want to. This query uses the sample_restaurants.restaurants data set in Atlas and the default index. Assume that the customers here are the boroughs of New York. Below is a query by the Queens tenant for a deli specializing in Sandwiches. It returns a number of documents but only those in Queens. Let me know if you have any questions. /** This query uses the sample_restaurants.restaurants dataset in Atlas and the default index. Assume that the customers here are the boroughs of New York. Below is a query by the Queens tenant for a deli specializing in Sandwiches. It reutrns a number of documents but only those in Queens. **/ { "index": "default", "compound": { "must": [ { "text": { "query": "Deli", "path": "name" } } ], "should": [ { "text": { "query": "Sandwiches", "path": "cuisine" } } ], "filter": [ { "text": { "query": "Queens", "path": "borough" } } ] } }
  • Guest
    Oct 25, 2020
    Are there any updates to this? Like Cassio, my company can't use Atlas Search for our multi-tenant application until this is possible. Thanks!
  • Guest
    Sep 23, 2020
    @Cassio Why can't you $match after the $search?
  • Guest
    Sep 9, 2020
    Hopefully once this feature is released I will be able to apply additional stages before $search with regular indexes since now any stages after don't use indexes e.g. to do $sort of results
  • Guest
    Jun 13, 2020
    Intuitiveness is not really the problem here. Not being able to perform a $search after a $match means that I can't use this on a multi-tenant database.
  • Guest
    May 27, 2020
    Thanks for creating this feature request Doug. I just wanted to say that our team strongly agrees here - adding the $search after a $match would be very intuitive.