mgeneratejs
mgeneratejs copied to clipboard
Verbatim ObjectId()
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.