ObjectId.createFromBase64()
On this page
Definition
Creates an ObjectId from a base64 value.
Compatibility
This method is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
Method Fields
The method accepts the following fields:
Field | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| String | Specifies a 16 character base64 value. For example,
| ||||||||||||||||
| Integer | Optional. Specifies a binary subtype.
|
Examples
The following examples show how to add an object identifier to a
document using ObjectId.createFromBase64()
and how the object
identifier appears in the output when retrieved.
Create Collection Containing Document with Base64 Number
The following example creates a collection named
objectIdentifierValuesFromBase64
:
db.objectIdentifierValuesFromBase64.insertOne( { _id: 0, objectIdentifierValue: ObjectId.createFromBase64( "SGVsbG8gV29ybGQh" ) } )
The objectIdentifierValue
field contains the object identifier
created from the base64 string specified in
ObjectId.createFromBase64()
.
Retrieve Document from Collection with Object Identifier
The following example retrieves the document:
db.objectIdentifierValuesFromBase64.findOne( { _id: 0 } )
Example output:
{ _id: 0, objectIdentifierValue: ObjectId("48656c6c6f20576f726c6421") }