Questions tagged «objectsize»

5
如何在Mongodb中获取单个文档的大小?
我遇到了mongo的奇怪行为,我想澄清一下... 我的要求很简单:我想在集合中获取单个文档的大小。我发现了两种可能的解决方案: Object.bsonsize-一些应返回字节大小的javascript方法 db.collection.stats()-其中有一行“ avgObjSize”,可在数据上生成一些“聚合的”(平均)大小视图。它仅表示单个文档的平均大小。 当我仅使用一个文档创建测试集合时,两个函数都返回不同的值。这怎么可能? 是否存在其他获取mongo文档大小的方法? 在这里,我提供一些我执行测试的代码: 我创建了新的数据库“ test”并输入仅具有一个属性的简单文档:type:“ auto” db.test.insert({type:"auto"}) stats()函数调用的输出:db.test.stats(): { "ns" : "test.test", "count" : 1, "size" : 40, "avgObjSize" : 40, "storageSize" : 4096, "numExtents" : 1, "nindexes" : 1, "lastExtentSize" : 4096, "paddingFactor" : 1, "systemFlags" : 1, "userFlags" : 0, "totalIndexSize" : 8176, …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.