Docs HomeMongoDB Manual

BinData()

On this page本页内容

Definition定义

Creates a binary data object.创建一个二进制数据对象。

BinData has the following syntax:具有以下语法:

BinData(<sub_type>,<buffer>)
Parameter参数Type类型Description描述
sub_typestringThe binary type.二进制类型。
Subtype子类Description描述
0Generic binary subtype通用二进制子类型
1Function函数
2Byte Array字节数组
3OLD UUID
4UUID
5MD5
128User defined用户定义
bufferstringThe buffer object containing binary data, must be a base 64 encoded string value.包含二进制数据的缓冲区对象必须是基64编码的字符串值。
Returns:返回值:A binary data object.二进制数据对象。

Examples实例

Insert a BinData() Object插入BinData()对象

Use the BinData() constructor to create the bdata variable.使用BinData()构造函数创建bdata变量。

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

Insert the object into the testbin collection.将对象插入到testbin集合中。

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

Query the testbin collection for the inserted document.testbin集合中查询插入的文档。

db.testbin.find()

You can see the binary buffer stored in the collection.您可以看到存储在集合中的buffer缓冲区。

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

Get the Length of BinData() Object获取BinData()对象的长度

Use the BinData() constructor to create the bdata variable.使用BinData()构造函数创建bdata变量。

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

Use .length() to return the bit length of the object.使用.length()返回对象的位长度。

bdata.length()

The returned value is:返回的值为:

16