问题描述
我使用的是 PHP mongo 命令:
I was using a PHP mongo command:
$db->command(array("create" => $name, "size" => $size, "capped" => true, "max" => $max));
而且我的收藏已经超出了他们假定的上限.我进行了修复:
And my collections grew way past their supposed capped limits. I put on a fix:
$db->createCollection($name, true, $size, $max);
目前,计数如此之低,我无法判断修复"是否有效.
Currently, the counts are so low I can't tell whether the 'fix' worked.
如何从 shell 或 PHP 判断一个集合是否有上限?我无法在 system.namespaces 中找到此信息.
How can you tell if a collection is capped, either from the shell or PHP? I wasn't able to find this information in the system.namespaces.
推荐答案
在 shell 中,使用 db.collection.stats().如果集合有上限:
In the shell, use db.collection.stats(). If a collection is capped:
> db.my_collection.stats()["capped"]
1
如果集合没有上限,则上限"键将不存在.
If a collection is not capped, the "capped" key will not be present.
以下是 stats() 对一个上限集合的示例结果:
Below are example results from stats() for a capped collection:
> db.my_coll.stats()
{
"ns" : "my_db.my_coll",
"count" : 221,
"size" : 318556,
"avgObjSize" : 1441.4298642533936,
"storageSize" : 1000192,
"numExtents" : 1,
"nindexes" : 0,
"lastExtentSize" : 1000192,
"paddingFactor" : 1,
"flags" : 0,
"totalIndexSize" : 0,
"indexSizes" : {
},
"capped" : 1,
"max" : 2147483647,
"ok" : 1
}
这是 MongoDB 1.7.4.
This is with MongoDB 1.7.4.
这篇关于如何判断一个集合是否有上限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!