ObjectId.createFromBase64()
On this page
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of MongoDB server.
Definition
Creates an ObjectId from a base64 value.
Syntax
Method Fields
The method accepts the following fields:
Field | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
base64String | String | Specifies a 16 character base64 value. For example,
"SGVsbG8gV29ybGQh" . | ||||||||||||||||
subType | 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") }