MongoDB stats() 函数返回位还是字节?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6082748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:06:01  来源:igfitidea点击:

Does the MongoDB stats() function return bits or bytes?

mongodb

提问by Mikey

When using MongoDB's .stats() function to determine document size, are the values returned in bits or bytes?

使用 MongoDB 的 .stats() 函数确定文档大小时,返回的值是以位还是字节为单位?

采纳答案by Andreas Jung

Bytes of course. Unless you pass in a scale as optional argument.

当然是字节。除非您将比例作为可选参数传递。

回答by Chris Fulstow

Running the collStatscommand - db.collection.stats() - returns all sizes in bytes, e.g.

运行collStats命令 - db.collection.stats() - 以字节为单位返回所有大小,例如

> db.foo.stats()
{
    "size" : 715578011834,  // total size (bytes)
    "avgObjSize" : 2862,    // average size (bytes)
}

However, if you want the results in another unit then you can also pass in a scaleargument.

但是,如果您希望在另一个单元中得到结果,那么您也可以传入一个scale参数。

For example, to get the results in KB:

例如,要获得以 KB 为单位的结果:

> db.foo.stats(1024)
{
    "size" : 698806652,  // total size (KB)
    "avgObjSize" : 2,    // average size (KB)
}

Or for MB:

或者对于 MB:

> db.foo.stats(1024 * 1024)
{
    "size" : 682428,    // total size (MB)
    "avgObjSize" : 0,   // average size (MB)
}