[SERVER-125] Field Matcher: field negative matcher (exclusion) Created: 05/Jul/09 Updated: 12/Jul/16 Resolved: 28/Oct/09 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | 1.1.3 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Eliot Horowitz (Inactive) | Assignee: | Mathias Stearn |
| Resolution: | Done | Votes: | 7 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
find( {} , { foo : -1 }) edit by mstearn: or {foo: false} {foo: -1}is treated as {foo: true} |
| Comments |
| Comment by Mathias Stearn [ 28/Oct/09 ] |
|
This is working in master as long as you don't need both include and exclude on the same query. If you need that comment on http://jira.mongodb.org/browse/SERVER-391 with the desired semantics. I went with a slightly different syntax than is suggested above. Rather than use -1 as the exclude value I used any "false" value. Currently that means false, null, and 0 of any numeric type. Anything else (including -1) is evaluated as true and means include. For sanity's sake, I suggest sticking to either true/false or 1/0. |
| Comment by Eliot Horowitz (Inactive) [ 14/Aug/09 ] |
|
I think that should uassert (throw a user exception) |
| Comment by Michael Stephens [ 14/Aug/09 ] |
|
What would be the semantics of mixing inclusion and exclusion at the same level? E.g. what would happen with: > find({}, {comments: 1, summary: -1}) Should that raise an error or should one of them take precedence? |
| Comment by Eliot Horowitz (Inactive) [ 14/Aug/09 ] |
|
resolved wrong ticket |
| Comment by Eliot Horowitz (Inactive) [ 14/Aug/09 ] |
|
thanks mike! |
| Comment by sandstrom [ 12/Aug/09 ] |
|
I was about to create a ticket for this myself. This is very useful for when implementing a database mapper, and you'd like to lazy-load certain fields. Would very much like to see support for this! |
| Comment by Wouter [ 09/Aug/09 ] |
|
I hope to see Sascha's suggestion implemented (support for negative matchers like "comments.content: -1" that refer to an array of embedded objects, and not to a single embedded object). |
| Comment by Sascha Matzke [ 05/Jul/09 ] |
|
I was just thinking if include/exclusion should work combined. Say I have a document which represents a blog entry with comments embedded. { _id: ... title: ... , summary: ..., content: ... , comments: [ { name: ..., title: ..., content: .... }, { ... }] } find( { _id: .... }, { comments: 1, comments.content: -1 }) So I want to load all comments for a specific _id, but exclude the content field from each comment. Could something like this make sense? |