BinData()
On this page本页内容
Definition定义
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.包含二进制数据的缓冲区对象必须是基64编码的字符串值。Returns:返回值:A binary data object.二进制数据对象。
Examples实例
Insert a BinData()
Object插入BinData()
对象
BinData()
ObjectUse 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()
对象的长度
BinData()
ObjectUse 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