-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Optimization
-
None
-
0
-
None
-
None
-
None
-
None
-
None
-
None
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.)