2

I'm trying to get all documents that don't have an _id in the array excluded.

db.sites.find({ "$expr": { '_id': { "$not": { "$in": "$excluded"} } } });

I'm not using $nin because it's not allowed under $expr.

I'm getting the following error message:

Error: error: {
    "ok" : 0,
    "errmsg" : "Expression $in takes exactly 2 arguments. 1 were passed in.",
    "code" : 16020,
    "codeName" : "Location16020"
}

Can I use $where for this instead?

0

1 Answer 1

6

The $in operator requires two arguments:

db.sites.find({ $expr: { $not: { $in: [ "$_id", "$excluded" ] } } })

Working example here

Sign up to request clarification or add additional context in comments.

2 Comments

@psykx please don't, there are just two $in operators in MongoDB and you tried to use the one for queries but you needed the one for aggregations
Aaahhhh. Ok. That makes sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.