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

Allow projection of one or multiple ObjectID sub-components.

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Query Optimization

      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.)

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            alice@gothcandy.com Dissatisfied Former User
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: