New Support for Positional Operator in Fields List Prevents Limited Inclusion of Fields in Selected Doc

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.2.0-rc1
    • Component/s: None
    • None
    • Linux
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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:

      {
      title: 'title', 'body': 'body'
      comments: [

      { id: 4, title: 'title', 'body': 'body', 'otherFieldOne': 'etc', 'otherFieldTwo': 'etc' }

      ]
      }

      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.

            Assignee:
            Scott Hernandez (Inactive)
            Reporter:
            Isaac Foster
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: