“0”是什么意思? MongoDB 的 BinData(0, “e8MEnzZoFyMmD7WSHdNrFJyEk8M=”) 中的意思是什么?
MongoDB shell 将二进制数据打印为 Base64 编码的字符串,包裹在看起来像函数调用的内容中:
"_id" : BinData(0,"e8MEnzZoFyMmD7WSHdNrFJyEk8M=")
“0”是什么意思?
The MongoDB shell prints binary data as a Base64-encoded string wrapped in what looks like a function call:
"_id" : BinData(0,"e8MEnzZoFyMmD7WSHdNrFJyEk8M=")
What does the "0" mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://docs.mongodb.org/manual/reference/mongodb- Extended-json/#binary
BSON BinData 数据类型通过 shell 中的 BinData 类表示。运行
help misc
以获取更多信息。来自 shell
您的情况下的
0
是 BSON 子类型http://bsonspec.org/ #/specation
此线程上有类似问题
http://groups.google.com/group/mongodb-dev/browse_thread/thread/1965aa234aa3ef1e
http://docs.mongodb.org/manual/reference/mongodb-extended-json/#binary
The BSON BinData datatype is represented via class BinData in the shell. Run
help misc
for more information.from the shell
The
0
in your case is the BSON subtypehttp://bsonspec.org/#/specification
Similar question on this thread
http://groups.google.com/group/mongodb-dev/browse_thread/thread/1965aa234aa3ef1e
Macrolinux 是对的,但是你必须小心他的例子,因为它会工作,但是是偶然的。
BinData() 的第一个参数是 BSON 二进制子类型,正如已经提到的,它是以下之一:
这些只是帮助器,以便反序列化器可以根据这些字节表示的内容以不同方式解释二进制数据除外
现在要了解示例为何错误,您会注意到调用 BinData(2, "1234") 不会存储表示字符串“1234”的二进制文件,原因有两个:
请参阅 bsonspec.org 了解更多信息。
Macrolinux is right but you have to be careful with his example as it will work but by accident.
The first argument to BinData() is the BSON binary subtype which, as has been mentioned is one of the following:
These are just helpers so that the deserializer can interpret the binary data differently depending on what those bytes represent except for the subtype 2 which is like the generic subtype but stores an int32 representing the length of the byte array as the first 4 bytes of data.
Now to see why the example is wrong you'll note that calling BinData(2, "1234") doesn't store the binary representing the string "1234" for two reasons:
See bsonspec.org for more information.
我相信它们对应于BSON子类型:
看起来
0
几乎总是一个有效的选择。I believe they they correspond to the BSON subtypes:
Looking at that, it appears that
0
is almost always a valid choice.