Document Size in MongoDb

妖精的绣舞 提交于 2019-11-30 10:13:22

As a general guide you can check the average size of documents in a collection collname using the avgObjSize value reported by collection stats():

db.collname.stats()

To find and count large documents you can use something similar to:

var maxSize = 1024;
var bigDocs = 0;
db.collname.find().forEach(
    function (doc) {
        var docSize = Object.bsonsize(doc);
        if (docSize >= maxSize) {
            bigDocs++;
            print(doc._id + ' is ' + docSize + ' bytes');
        }
    }
)
print("Found " + bigDocs + " documents bigger than " + maxSize + " bytes")

Note that both these examples are using the MongoDB BSON representation, which will vary from the size required to represent the same data in other databases.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!