[SERVER-6800] New Support for Positional Operator in Fields List Prevents Limited Inclusion of Fields in Selected Doc Created: 19/Aug/12 Updated: 15/Feb/13 Resolved: 20/Aug/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 2.2.0-rc1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Isaac Foster | Assignee: | Scott Hernandez (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | Linux |
| Participants: |
| Description |
|
When using the positional operator ($) in the field selection list of a find query to limit the embedded documents that are returned (new feature from https://jira.mongodb.org/browse/SERVER-828), any other field inclusions for the embedded document are ignored (unless I'm doing it wrong, although I don't think I am). I put a gist on gisthub that illustrates (https://gist.github.com/3398285), but a brief illustration would be: Blog post has multiple comments, you want to select the blog, along with the comment that has id 4. You also want to limit the fields of the comment that are returned to the title and body: db.BlogPosts.find( {"comments.id": 4}, {"title":1, "body":1, "comments.$":1, "comments.title":1, "comments.body":1}); The BlogPost is returned with its own title and body, and with just the one comment, but the entire comment is returned: { ] This isn't a big deal in a lot of situations, but if there were a number of embedded documents in the comment document, you might want to exclude them. |
| Comments |
| Comment by Scott Hernandez (Inactive) [ 20/Aug/12 ] |
|
Yep, it is working as designed and I think exclusion is what you want to remove the fields you don't want from the embedded doc. |
| Comment by Isaac Foster [ 20/Aug/12 ] |
|
Sure, happy to, although I'm not sure I got my issue across. The issue wasn't with mixing inclusion/exclusion clauses for retrievedFields (i.e. {"embedded.name": 1, "embedded.body": 0}): it was "mixing" inclusion clauses in the retrievedFields object, when one of those projections uses the positional operator to return only the matched embedded document, and the other is to limit the returned fields in said document (i.e. {"embedded.$": 1, "embedded.name": 1}). Just based on intuition (as far as that matters) I would expect the result set to include only the name field of the matched embedded document, but instead the whole matched embedded document is returned. I put an updated example below. Since the ability to use the positional operator to limit to the matched embedded document is a new feature in 2.2 (well, 2.1.2, but coming out in 2.2), I figured this was a bug. Not sure if that's what you thought I meant. If that behavior is expected and I'm just missing something, let me know and I'll make a new feature request ticket. Thanks! UPDATED EXAMPLE: , {"embedded.$":1, "embedded.name":1}) ] //GETTING ] |
| Comment by Scott Hernandez (Inactive) [ 20/Aug/12 ] |
|
Isaac, this sounds more like a feature request to allow mixing or inclusion/exclusion clauses for projection (retrievedFields). Can you create a new improvement request for that, if that is what you want. |