Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

ObjectId.createFromBase64()

On this page

  • Definition
  • Syntax
  • Examples

Creates an ObjectId from a base64 value.

ObjectId.createFromBase64( <base64String> [ , <subType> ] )

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.

Value
Description
0
Generic binary subtype
1
Function
2
Byte array (deprecated)
3
Old UUID (deprecated)
4
UUID
5
MD5
128 through 255
User defined

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.

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().

The following example retrieves the document:

db.objectIdentifierValuesFromBase64.findOne( { _id: 0 } )

Example output:

{
_id: 0,
objectIdentifierValue: ObjectId("48656c6c6f20576f726c6421")
}
← ObjectId()