Mongodb Atlas Search if the field exists

210 Views Asked by At

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

I tried using must, mustnot, if exists nothing seems to work

1

There are 1 best solutions below

0
amy On

Using a mustNot clause with an equals operator worked for me:

[
  {
    $search: {
      index: <name of search index>,
      compound: {
        mustNot: [
          {
            equals: {
              path: <boolean field>,
              value: true,
            },
          },
        ],
        filter: [
          {
             // filter operations
          }
        ]
      },
    },
  },
]