Atlas Search with exclude


I would like to perform and query in atlas search and exclude some documents.
Is it possible to have a query like “not equals” or “does not contain”?

I could probably add a second stage where I exclude the documents from the search result, but this would not be as performant, because I can not use an index. Additionally, the $searchMeta feature could not be used anymore.


Hi @Mathias_Mahlknecht ,

You can use the mustNot option in the compound operator to filter out documents that match a specified equals clause. Something like:

  $search: {
    "compound": {
         "mustNot": {
          "equals": {
            "path": "_id",
            "value": ObjectId("xxxxx")

Hope this helps!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.