我有一个上限集合,它是在 java 代码中创建的:
this.collection = db.createCollection("stat", new BasicDBObject("capped", true).append("size", 200000000).append("max", 1000000));
现在在这个集合的统计数据中,我们有:
/* 0 */
{
"ns" : "myDatabase.stat",
"count" : 12212,
"size" : 2146416,
"avgObjSize" : 175,
"storageSize" : 200003584,
"numExtents" : 1,
"nindexes" : 4,
"lastExtentSize" : 200003584,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 2272928,
"indexSizes" : {
"_id_" : 1259104,
"downloaded_1" : 335216,
"submitted_1" : 318864,
"retries_1" : 359744
},
"capped" : true,
"max" : 1000000,
"ok" : 1
}
如果我尝试使用以下代码在集合中插入文档:
BasicDBObject doc = new BasicDBObject().
append("downloaded", new Date(0)).
append("sessionId", sessionId).
append("group", group);
collection.update(new BasicDBObject("_id", request.getUrl()), new BasicDBObject("$set", doc), true, false);
我发现了这个错误:
com.mongodb.WriteConcernException: { "serverUsed" : "/127.0.0.1:27017" , "lastOp" : { "$ts" : 0 , "$inc" : 0} , "connectionId" : 16420 , "err" : "failing update: objects in a capped ns cannot grow" , "code" : 10003 , "n" : 0 , "ok" : 1.0}
at com.mongodb.CommandResult.getException(CommandResult.java:77)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:110)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:102)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:327)
at com.mongodb.DBCollection.update(DBCollection.java:178)
at com.mongodb.DBCollection.update(DBCollection.java:209)
at com.srg.hydra.monitoring.HydraStatistics.insert(HydraStatistics.java:63)
at com.srg.hydra.HydraSite.onSubmit(HydraSite.java:91)
at ru.decipher.site.AbstractSite.submit(AbstractSite.java:198)
at com.srg.hydra.Eip.start(Eip.java:48)
at com.srg.hydra.runner.DefaultHydraRunner.doCrawling(DefaultHydraRunner.java:180)
at com.srg.hydra.runner.DefaultHydraRunner$1.run(DefaultHydraRunner.java:155)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
我究竟做错了什么?以及如何解决?(排除到 .drop() 这个集合并重新创建)感谢您的回答!