我想将集合限制为 1MB 或 300 条记录,以先到者为准。
PRIMARY>db.runCommand({"convertToCapped":"cache",'size':1024*1024, 'max':300});
{ "ok" : 1 }
PRIMARY>db.cache.isCapped();
true
到目前为止,一切都很好。一段时间后,我在集合使用了一点(插入新记录等)后重新签入
PRIMARY> db.cache.count();
513
嗯什么?上次我检查时,513 > 300。请注意,“封顶”是在计数超过 300 之前执行的。
PRIMARY> db.cache.validate();
{
"ns" : "streamified.cache",
"capped" : 1,
"max" : 2147483647,
"firstExtent" : "16:7279e000 ns:streamified..tmp.convertToCapped.cache",
"lastExtent" : "16:7279e000 ns:streamified..tmp.convertToCapped.cache",
"extentCount" : 1,
"datasize" : 858104,
"nrecords" : 513,
"lastExtentSize" : 1052672,
"padding" : 1,
"firstExtentDetails" : {
"loc" : "16:7279e000",
"xnext" : "null",
"xprev" : "null",
"nsdiag" : "streamified..tmp.convertToCapped.cache",
"size" : 1052672,
"firstRecord" : "16:7279e0b0",
"lastRecord" : "16:72871444"
},
"deletedCount" : 1,
"deletedSize" : 186184,
"nIndexes" : 0,
"keysPerIndex" : {
},
"valid" : true,
"errors" : [ ],
"warning" : "Some checks omitted for speed. use {full:true} option to do more thorough scan.",
"ok" : 1
}
我不擅长阅读这个输出,但上面的“最大值”看起来有点奇怪。除此之外,我不确定会出现什么问题......