[SERVER-9] negated $in operator Created: 11/Apr/09  Updated: 12/Jul/16  Resolved: 26/May/09

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: 0.9.3
Fix Version/s: 0.9.3

Type: New Feature Priority: Minor - P4
Reporter: Liam Staskawicz Assignee: Aaron Staple
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

It would be very nice to be able to use a negated version of the existing $in query operator. If I have an array of values I know I don't want to match against, I'd ideally be able to use a query along the lines of

db.mycoll.find({_id:{'not $in':[some, array]}})



 Comments   
Comment by Aaron Staple [ 13/Apr/09 ]

I've implemented $nin, tested in nin.js.

Comment by Eliot Horowitz (Inactive) [ 13/Apr/09 ]

Yeah - it ideally shouldn't be returned.
Though if its really annoying, maybe we should just assert and see if it comes up.

Comment by Aaron Staple [ 13/Apr/09 ]

Per previous comment, I'm guessing that the object should not be returned. The example isn't so different from the previous one, but the implementation is more complicated.

Comment by Aaron Staple [ 13/Apr/09 ]

Ok, should { a: [

{b: 1 }

,

{ b: 2 }

] } be returned with { 'a.b': {$ne:1}} or not?

Comment by Eliot Horowitz (Inactive) [ 13/Apr/09 ]

I think we should change the meaning of $ne with arrays.

{ a : [ 1 , 2] }

should not be returned with { a :

{ $ns : 1 }

}

Comment by Aaron Staple [ 13/Apr/09 ]

I'm planning to call this new operator $nin.

Do we want $nin to be equivalent to several instances of the $ne operator ( { a:

{ $nin: [ 1, 2, 3 ] }

} <=> { a:

{ $ne: 1, $ne: 2, $ne: 3 }

} )?

If so, we should be aware of $ne's behavior matching multikey arrays. Currently, { a:

{ $ne: 1 }

} will match

{ a: [ 1, 2 ] }

because 2 != 1. Similaraly, { a:

{ $nin: [ 1, 2 ] }

} would match

{ a: [ 1, 3 ] }

as well as

{ a: [ 1, 2 ] }

since these are each currently matched by { a:

{ $ne: 1, $ne: 2 }

}.

Do we want to change the meaning of $ne, use some other definition for $nin, or just proceed with the proposed "simple" definition of $nin?

Generated at Thu Feb 08 02:52:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.