Mongodb 文档大小 [英] Mongodb Document size
问题描述
请确认一个简短的问题.
A quick question please to be sure.
我的收藏来宾中有以下文档示例
I have the following example of document in my collection guest
"_id" : "JM15061985",
"last_name" : "Michel",
"first_name" : "Justine",
"gender" : "Female",
"title" : "Mme",
"telephone" : 3375,
"mail" : "justine.michel@yahoo.com",
"language" : "French",
"birthday" : ISODate("1985-06-14T22:00:00Z"),
"status" : "VIP",
"company" : "Test",
"address" : [
{
"street" : "45 Avenue de Paris",
"city" : "Nice",
"zip_code" : "06072",
"country" : "France"
},
{
"street" : "12 square xvy",
"city" : "Toulon",
"zip_code" : "83072",
"country" : "France"
},
]
我知道 Mongodb 中的一个文档不能超过 16Mb.所以我的基本问题是:16Mb 到底代表什么?(有什么例子吗?)在我的例子中,每个地址都被视为一个文档还是这只是一个文档?
I know that one document ins Mongodb can't exceed 16Mb. So my basics questions are : What does 16Mb represents really? (any exemple maybe?) In my example, is each address considered as a document or this is only one document?
推荐答案
16MB 是 BSON 文档 代表您的文档.这包括嵌套对象,例如您的 address
示例,以及键名(不仅仅是值).
16MB is the maximum size of the BSON-document that represents your document. This includes nested objects, like your address
example, and also key names (not just the values).
每个文档属性也有一些开销,如此处所述.
There's also some overhead per document property, as explained here.
要检查特定 JS 对象的 BSON 文档大小,如果您碰巧使用 Node.js,则可以使用 bson
模块:
To check BSON document size for a particular JS object, and if you happen to use Node.js, you can use the bson
module:
var BSON = new (require('bson')).BSONPure.BSON();
var bson = BSON.serialize(obj, false, true, false);
console.log('bson size', bson.length);
其他编程语言应该也有类似的解决方案.
There should be similar solutions for other programming languages.
这篇关于Mongodb 文档大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!