$ne operator explanation

{usertype:{$ne:“Subscriber”,$ne:“Customer”}}
Per my understanding, the $and operator is implied. Thus, why does this filter return documents with a usertype equal to Subscriber? I would seem to me that this filter should return documents where usertype is not equal to Subscriber and not equal to Customer.

Hi @bsheely,

The $ne operator checks only for one condition.So, in your case it is only taking the last condition {$ne: “Customer”} into consideration and that is why your query is returning documents where usertype is equal to Subscriber.

You can use $nin operator to find the documents where usertype is not equal to Subscriber and Customer.

In compass, you can check the details of your query in the Explain Plan tab.

Please check the screenshot to understand the query using $ne operator.

If you still have any doubts, please let me know.

Thanks,
Sonali