Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Binary.createFromHexString()

On this page

  • Definition
  • Syntax
  • Examples

Creates a binary object from a hexadecimal value.

Binary.createFromHexString( <hexadecimalString> )

The hexadecimalString field specifies a string that contains a hexadecimal value. For example, "64c13ab08edf48a008793cac".

The following examples show how to add a binary object to a document using Binary.createFromHexString() and how the binary object appears in the output when retrieved.

The following example creates a collection named binaryObjectsFromHexString:

db.binaryObjectsFromHexString.insertOne( {
_id: 0,
binaryObject: Binary.createFromHexString( "64c13ab08edf48a008793cac" )
} )

The binaryObject field contains the binary object created from the string specified in Binary.createFromHexString().

The following example retrieves the document:

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

Note

Starting in mongosh 2.0.0, binary values are shown as Binary.createFromBase64( <base64String> ) values instead of Binary( Buffer.from( <base64String> ) ) values. This only changes the display of binary values.

Example output, which shows the number in base64:

{
_id: 0,
binaryObject: Binary.createFromBase64("ZME6sI7fSKAIeTys")
}
← Binary.createFromBase64()