Atlas Search if field does not exists

Hi all,
I am new to mongodb using atlas search for my query. I want to return document based on a condition where if the field exists it should be false if the field does not exists it should return the document based on filters. Basically return the documents where field is False or where the field doesn’t exist at all. If using find we can use like this
q[‘active’] = {‘$ne’: True}
How can we achieve same using atlas search

Hello @Shradha_Nambiar,

In Atlas Search, you can use the compound operator along with exists and the equals operator to filter documents based on both the field’s non-existence and its value.

With the help of the above operator, you can form a query that can return the resultant documents as per your conditions. Here is the example query for your reference:

[
  {
    $search: {
      index: "default",
      "compound": {
        "should": [
          {
            "equals": {
              "path": "field_name",
              "value": false
            }
          },
          {
            "compound": {
              "mustNot": {
                "exists": {
                  "path": "field_name"
                }
              }
            }
          }
        ]
      }
    }
  }
])

However, May I ask about your use case or any specific requirements you have? This will help us provide more tailored advice on whether Atlas Search or traditional queries are the better fit. If your use case doesn’t involve full-text search or ranking requirements, sticking with regular MongoDB queries might provide a more straightforward solution.

Looking forward to your response.

Best regards,
Kushagra