Docs Menu
Docs Home
/
MongoDB Manual
/ / /

BinData()

On this page

  • Definition
  • Examples

Creates a binary data object.

BinData has the following syntax:

BinData(<sub_type>,<buffer>)
Parameter
Type
Description
sub_type
string

The binary type.

Subtype
Description
0
Generic binary subtype
1
Function
2
Byte Array
3
OLD UUID
4
UUID
5
MD5
128
User defined
buffer
string
The buffer object containing binary data, must be a base 64 encoded string value.
Returns:A binary data object.

Use the BinData() constructor to create the bdata variable.

var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")

Insert the object into the testbin collection.

db.testbin.insertOne( { _id : 1, bin_data: bdata } )

Query the testbin collection for the inserted document.

db.testbin.find()

You can see the binary buffer stored in the collection.

{
_id: 1,
bin_data: Binary(Buffer.from("81fd547317474c9d8743f10642b3bb99", "hex"), 0)
}

Use the BinData() constructor to create the bdata variable.

var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")

Use .length() to return the bit length of the object.

bdata.length()

The returned value is:

16

Back

Object Constructors and Methods

On this page