MongoDB 中字符串类型的大小 [英] Size of a string type in MongoDB

查看:92
本文介绍了MongoDB 中字符串类型的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 ObjectIDs 在 MongoDB 中是 12 字节.而且我知道 numbers 是 64 位的.但是如何找出保存的 string

I know that ObjectIDs are 12-bytes in MongoDB. And I know that numbers are 64-bit. But how do I find out the size of a saved string

推荐答案

http://bsonspec 上的 bson 规范.org/spec.html 是一个很好的起点.

特别重要的是要意识到 BSON 确实 具有整数类型,包括 32 位整数,这甚至是默认值,尽管 JavaScript 使用 64 位浮点数 - MongoDB 使用 JavaScript很多,但它不是在 JavaScript 中并且有不同的类型.真整数的存在非常重要,否则 $inc 在大数上将不起作用.

In particular, it's important to realize that BSON does have integer types, including 32 bit integers which is even the default, despite the fact that JavaScript uses a 64 bit floating point numbers - MongoDB uses JavaScript a lot, but it's not written in JavaScript and has different types. The existence of true integers is quite important, otherwise a $inc on a large number wouldn't work.

回答你的问题:字符串被存储为 UTF-8 编码的字符串,前面有一个零终止符和 32 位长度,当然还有 1 字节类型指示符和元素名称.请记住,对象有额外的开销.

To answer your question: strings are stored as UTF-8 encoded strings with a zero terminator and a 32-bit length in front, plus the 1-byte type indicator and the element name, of course. Keep in mind that objects have additional overhead.

这篇关于MongoDB 中字符串类型的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆