bson | objectId functions
This section describes functions for working with BSON objectId values.
BSON (Binary JSON) is a binary representation of JSON-like documents used primarily by MongoDB. Some systems that implement MongoDB-compatible APIs, such as Azure Cosmos DB, also support BSON documents.
A BSON objectId is a 12-byte identifier that consists of:
•A 4-byte timestamp representing the number of seconds since the Unix epoch (1970-01-01T00:00:00Z).
•A 5-byte random value generated once per client-side process.
•A 3-byte incrementing counter per client process, initialized to a random value. This counter increments for each new ObjectId generated by the same process, ensuring uniqueness.
MapForce supports the following functions for working with BSON ObjectIds:
•objectId-datetime: Extracts an ObjectId's creation date and time (in UTC), converted from the stored timestamp.
•objectId-random: Extracts the random value from an ObjectId.
•objectId-ordinal: Extracts the incrementing counter (ordinal) from an ObjectId.
•to-objectId: Creates an ObjectId using the specified creation date, random value, and counter.
How BSON ObjectIds are handled in MapForce
BSON ObjectIds are converted automatically from and to hex strings. For details, see the table below. For an example, see the description of the to-objectId function.
Conversion | What happens |
|---|---|
bson.objectId > string | Produces a 24-character hexadecimal string representing the 12-byte ObjectId. |
string > bson.objectId | Parses a 24-character hex string and builds a 12-byte ObjectId. An error occurs if the input is not a valid hex string of correct length. |
Useful links