ObjectId generation inside aggregation and update expressions
Parent: MongoDB Aggregation Pipeline · Published reference · snapshot 2026-10-29
↓ Facts as markdownall context files
Source-anchored research for ObjectId generation inside aggregation and update expressions. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
How it works
- Using $createObjectId in an update does not remove the immutability of an existing stored _id. Generate an ordinary identifier field when updating stored documents; the official example that supplies a new _id operates on a view projection. (medium confidence) [source]
- A first-hand experiment using MongoDB 8.3.11 reports that $createObjectId fails when FCV is 8.2 and succeeds after FCV is set to 8.3. Treat this as a reported compatibility observation, pending independent runtime reproduction. (low confidence) (verified as of 2026-10-11) [source]
Problems, failure modes and limitations
- The wire expression is {$createObjectId: {}}. Only an empty object is accepted; other arguments fail with FailedToParse. A published first-hand experiment reproduces rejection of {x: 1}. (medium confidence) [source]
Facts and statements
- MongoDB introduced $createObjectId in 8.3 to generate new random ObjectId values within aggregation pipelines and expression-based updates. (medium confidence) [source]
- $createObjectId generates a value without a source-value input; $toObjectId converts an existing value. NoSQLBooster documents this distinction alongside its $.createObjectId() helper. (medium confidence) [source]
- Generation occurs for output documents: the official view example assigns _id: {$createObjectId: {}}, and the C# LINQ example assigns a new NewId for each output document using Mql.CreateObjectId(). (medium confidence) [source]
- A supported update pattern is db.items.updateMany({}, [{$set: {generatedId: {$createObjectId: {}}}}]); this combines the documented expression-based-update support with the documented pipeline $set stage. This is a documentation-derived example, not a locally executed test. (medium confidence) [source]
- In a Stack Overflow exchange, a commenter reported the same ObjectId in all array objects. The answer author acknowledged the issue and updated the answer, whose code uses $function with a JavaScript body returning an ObjectId for each mapped element. (low confidence) [source]
- NoSQLBooster 11.1 exposes $.createObjectId() as an aggregation expression helper; its release announcement dates this support to September 30, 2026. (low confidence) (verified as of 2026-09-30) [source]
- The operator’s implementation ticket lists fix version 8.3.0-rc0 and separately links an SBE-support task. The separate task establishes an implementation question; it does not by itself establish current performance or execution-engine behavior. (medium confidence) [source]
Children
- Per-document nondeterministic expression evaluation (frontier)
- ObjectId generation versus conversion (frontier)
- Generated identifiers in views (frontier)
- Feature compatibility gating for new expressions (frontier)
Frontier under this node: Feature compatibility gating for new expressions, Generated identifiers in views, ObjectId generation versus conversion, Per-document nondeterministic expression evaluation