$ ne is usually used for a value. But if you want to exclude multiple items in array, you can use $ nin
For example I have this model:
{
"_id": "5a934e000102030405000000",
"key": 1
},
{
"_id": "5a934e000102030405000001",
"key": 2
},
{
"_id": "5a934e000102030405000002",
"key": 3
},
{
"_id": "5a934e000102030405000003",
"key": 4
},
{
"_id": "5a934e000102030405000004",
"key": 5
}
And I want exclude key:3 and key5:
db.collection.find({
key: {
"$nin": [
3,
5
]
}
})
Now this query return a correct result:
[
{
"_id": "5a934e000102030405000000",
"key": 1
},
{
"_id": "5a934e000102030405000001",
"key": 2
},
{
"_id": "5a934e000102030405000003",
"key": 4
}
]
I hope this solution helps you.