mgeneratejs icon indicating copy to clipboard operation
mgeneratejs copied to clipboard

Verbatim ObjectId()

Open nurih opened this issue 1 year ago • 0 comments

With the alias $oid it is not possible to express a constant ObjectId value, since the framework would ignore the value, even if a template included the ObjectId value.

{"$objectid": "000000001111111122222222"}

// would result in a random new ObjectId

{"$oid": "648750fb87f87cb95eeccf6c"} // new one each time

This PR introduces the optional value to allow templates to include verbatim ObjectId values.

New behavior triggered if optional value is supplied:

{"_id": {"$objectid": {"value": "000000001111111122222222"}}
// Result would be the constant
{"_id": {"$oid": "000000001111111122222222"}}

Existing behavior remains as is:

{"_id": "$objectid"}

The above results in a new ObjectId generated each time.

nurih avatar Jun 12 '23 18:06 nurih