当从 mongoDB 中的上限集合中删除文档时,它是否通过错误? [英] when remove document from capped collection in mongoDB, it through an error?
问题描述
我正在为我的新项目学习 mongoDB.我创建了一个上限集合,但是当我尝试从下面的 mongoDB 中的上限集合中删除文档时出现错误,
I am learning mongoDB for my new project. I created a capped collection but I am getting an error while I am trying to remove document from capped collection in mongoDB which is below,
db.mycol.remove({"_id":ObjectId("57bef716e5ff2cbb540e403b")})
db.mycol.remove({"_id":ObjectId("57bef716e5ff2cbb540e403b")})
写结果({"nRemoved" : 0,写错误":{代码":20,"errmsg" : "无法从上限集合中删除:mytestdb.myc哦"}})
WriteResult({ "nRemoved" : 0, "writeError" : { "code" : 20, "errmsg" : "cannot remove from a capped collection: mytestdb.myc ol" } })
请帮我解决这个问题.
先谢谢你.
推荐答案
原因:您的收藏集已封顶,无法执行此操作.详细信息:限制
Cause: your Collection is Capped, can not do this action. Details: Restrictions
另外,通过命令检查您的集合是否有上限?:
Addition, check your Collection is Capped? by command:
db.mycol.isCapped()
通过命令检查您的 MongoDB 版本:
check your MongoDB version by command:
db.version()
[解决]创建一个没有上限的新集合并复制您的所有文档.
[Solve] Create a new Collection not Capped and copy all your document.
复制、替换您的集合名称并粘贴到您的终端中.
Copy, replace your collection name and paste in your terminal.
// replace <mycol> by <your collections name>
db.createCollection( "mycol_temp")
var cur = db.mycol.find()
while (cur.hasNext()) {
mycol = cur.next();
db.mycol_temp.insert(logItem);
}
db.mycol.drop()
db.mycol_temp.renameCollection("mycol")
现在,通过重新排列集合来接受 update() 或 remove() 文档.
Now, update() or remove() document is accepted via re-arranging collections.
这篇关于当从 mongoDB 中的上限集合中删除文档时,它是否通过错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!