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

Allow projection of one or multiple ObjectID sub-components.

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Aggregation Framework
    • Labels:
      None

      Description

      In a similar, though more generalized vein to SERVER-9406 (treating ObjectIDs as dates) and SERVER-24947 (to- typecasting mechanisms), allowing for the projection of any (or all) sub-component(s) of an ObjectId into discrete fields would allow for easy additional processing on these values. Practical use case: aggregate group results based on machine (hardware ID ± PID) that generated the record, useful for log or other hardware-dependent statistical analysis.

      The syntax recommendation comes in two forms, short single-component, or multi-component embedded document:

      {$project: {parts: {$decomposeId: {_id: true}}}
      

      This would project all components from an ObjectId into an embedded document named parts:

      {parts: {ts: ISODate, host: int, pid: int, counter: int}
      

      To retrieve specific values, pass a document instead of true:

      {$project: {parts: {$decomposeId: {_id: {host: true, pid: true}}}
      

      {parts: {host: int, pid: int}
      

      To retrieve a specific singular value, pass just its name instead of true:

      {$project: {created: {$decomposeId: {_id: "ts"}}}
      

      {created: ISODate(...)}
      

      As mentioned in the first paragraph, this is to facilitate use of group operations on ObjectID components. As a side-effect, this would have also resolved SERVER-9406. (Though automatic casting is nice, explicit is better than implicit.)

        Attachments

          Activity

            People

            Assignee:
            backlog-server-query Backlog - Query Team
            Reporter:
            amcgregor Dissatisfied Former User
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Dates

              Created:
              Updated: