Database Manual / Reference / mongosh Methods / Object Constructors

HexData() (mongosh method方法)

Definition定义

Creates a binary data object from hexadecimal data.从十六进制数据创建二进制数据对象。

Syntax语法

HexData() has the following syntax:具有以下语法:

HexData( <subType>, <buffer> )
Returns:返回Binary data object.二进制数据对象。

Command Fields命令字段

The command takes these fields:该命令包含以下字段:

Field字段Type类型Necessity必要性Description描述
subTypeinteger整数Required必需

Specify a data subtype:指定数据子类型:

Number数字Description描述
0Generic binary subtype通用二进制子类型
1Function data功能数据
2Binary (old)二进制(旧)
3UUID (old)
4UUID
5MD5
6Encrypted BSON value加密的BSON值
7

Compressed time series data压缩时间序列数据

New in version 5.2.在版本5.2中新增。

8Sensitive data, such as a key or secret. MongoDB does not log literal values for binary data with subtype 8. Instead, MongoDB logs a placeholder value of ###.敏感数据,如键或秘密。MongoDB不会记录子类型为8的二进制数据的文字值。相反,MongoDB会记录一个占位符值###
9Vector data, which is densely packed arrays of numbers of the same type.矢量数据,它是由同一类型的数字组成的密集数组。
128Custom data自定义数据
bufferstring字符串Required必需Hexadecimal data. The string is decoded up to the first character that is not a valid hexadecimal digit. You can use upper or lower case letters in the hexadecimal string.十六进制数据。字符串被解码到第一个不是有效十六进制数字的字符。您可以在十六进制字符串中使用大写或小写字母。

Examples示例

1

Create the example collection创建示例集合

Use HexData() to insert a document with binary data created from a hexadecimal string into a test collection:使用HexData()将包含从十六进制字符串创建的二进制数据的文档插入到测试集合中:

db.hexCollection.insertOne( {
_id: 0, hexField: HexData( 0, "123456abcdef" )
} )
2

Retrieve the document检索文档

To return the document, run the following find command:要返回文档,请运行以下find命令:

db.hexCollection.find()

Output shows the hexField value as a base 64 number using Binary.createFromBase64():输出使用Binary.createFromBase64()hexField值显示为基数64的数字:

[ { _id: 0, hexField: Binary.createFromBase64('EjRWq83v', 0) } ]

Learn More了解更多