Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1608

Retrieving only selected document(s) from within an embedded array

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None

      I am not completely certain, but I believe at present it is not possible to return only selected document(s) from within an embedded array. For instance;

      document A {
      user_name: example_user,
      remaining_tokens: 40,
      assignees_array[

      {UUID: 7, next_checkin_time: <some_unix_time>, expires: <some_unix_time>}

      ,

      {UUID: 1F0, next_checkin_time: <some_unix_time>, expires: <some_unix_time>}

      , ... ]
      }

      If my program has knowledge of the UUID, and wishes to see only the sub-document (e.g. If we queried for UUID 7 and then read the next_checkin_time and some other fields).

      db.my_collection.find("assignees_array.UUID":"1F0"} =>

      {UUID: 1F0, next_checkin_time: <some_unix_time>, expires: <some_unix_time>}

      At present I do not know of a way that it is possible to achieve this, as it returns the entire parent document and all array elements (losing some of the benefit of selecting on the basis of the embedded document's UUID), so you have to iterate to find the correct item.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            m.savy m savy
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: