当前位置: 首页 > 知识库问答 >
问题:

为什么在mongodb中更新文档时出现错误代码10003?我使用的是mongodb 3.2版

令狐唯
2023-03-14
db.FirstTry.update({"id":1},{$set:{"Name":"Selvah"}});

我犯了这样的错误

{“message”:“WriteError({'code':10003,'index':0,'errmsg':'Cannot change the size of a document in a capped collection:72!=71','op':{'q':{'id':1},'u':{'set':{'Name':'Selvah'},'multi':false,'upsert':false},'stack:“script:1:13}”

共有2个答案

终波涛
2023-03-14

我想这解决了你的问题http://www.solidsyntax.be/2016/03/26/MongoDB-Cannot-change-the-size-of-a-document-in-a-capped-collection/

官方文档列出了有关使用封顶收藏的信息:https://docs.mongodb.com/manual/core/capped-collections/#restrictions-和建议

萧浩漫
2023-03-14

封顶集合中文档的大小是固定的,因此不能在文档中插入新字段。您必须创建一个新的临时集合,将所有数据从旧集合复制到新集合,并添加新字段。

大概是这样的:

db.createCollection( "logItems_temp", { capped: true, size: 100000 } )
var cur = db.logItems.find()
while (cur.hasNext()) {
  logItem = cur.next(); 
  if(logItem.name == null){
      logItem.name = selvah;
  }
  db.logItems_temp.insert(logItem);
}
db.logItems.drop()
db.logItems_temp.renameCollection("logItems")
 类似资料: