Check if every element in array matches condition

The query you want is this:

db.collection.find({"users":{"$not":{"$elemMatch":{"user":{$nin:[1,5,7]}}}}})

This says find me all documents that don’t have elements that are outside of the list 1,5,7.

Leave a Comment