MongoDb中的文档大小 [英] Document Size in MongoDb
问题描述
将来想切换到DynamoDB,但要确保我的文档在1KB以下,因为它们每KB收费.有没有一种快速的方法来知道集合中文档的大小?
作为一般指南,您可以使用集合报告的avgObjSize
值检查集合 collname 中文档的平均大小. c1>:
db.collname.stats()
要查找和计算大型文档,您可以使用类似于以下内容的东西:
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")
请注意,这两个示例都使用MongoDB BSON 表示形式,该表示形式与表示其他数据库中相同数据所需的大小有所不同. /p>
Thinking of switching to DynamoDB in future, but want to make sure my documents are under the 1KB, as they charge per KB. Is there a quick way to know how large a document is in a collection?
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.
这篇关于MongoDb中的文档大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!