[SERVER-15612] $in might cover "not exists" with a special value Created: 13/Oct/14 Updated: 09/Jul/16 Resolved: 13/Oct/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Mustafa Dokumac? | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
Example Data:
Example Query:
Example Resultset:
|
| Comments |
| Comment by Mustafa Dokumac? [ 13/Oct/14 ] | |||
|
Thank you for quick respond and helping me. You can avoid this kind of time stealing issues / questions by documenting the behaviour at one of these pages: http://docs.mongodb.org/manual/reference/operator/query/in/ There is an example for "exists and not equal to one of these" ($exists & $nin) but no example for "not exists or equal to one of these". Have a nice day. | |||
| Comment by Thomas Rueckstiess [ 13/Oct/14 ] | |||
|
Hi Mustafa, While you cannot nest special operators inside an $in query, you can achieve this behavior (with a slight caveat) with the following query:
Instead of {$exists: false}, you can use the value null, which will also return non-existing fields. The caveat is that it will also return documents that have the value field2 set to null explicitly. If you treat null and "non-existing" values as equivalent in your schema however, then this query does what you're asking for. Regards, |