mongodb建索引遇到的一个错误解决办法

Error creating index

Safemode detected an error 'BSONObj size: 0 (0x00000000) is invalid. Size must be between 0 and 16793600(16MB) First element: EOO'. (Response was { "err" : "BSONObj size: 0 (0x00000000) is invalid. Size must be between 0 and 16793600(16MB) First element: EOO", "code" : 10334, "n" : 0, "connectionId" : 37, "ok" : 1.0 }).

Type: MongoDB.Driver.MongoSafeModeException

Stack:    在 MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode)

   在 MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)

   在 MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options)

   在 MongoDB.Driver.MongoCollection.Insert[TNominalType](TNominalType document, MongoInsertOptions options)

   在 MongoDB.Driver.MongoCollection`1.Insert(TDefaultDocument document, MongoInsertOptions options)

   在 MongoDB.Driver.MongoCollection.CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options)

   在 MangoUI.MIndexes.Create(String db, String col, String name, BsonDocument fields, Boolean unique, Boolean dropDups, Boolean background)

   在 MangoUI.WinIndexNew.btnCreate_Click(Object sender, EventArgs e)

Inputs:: 

Command:  getlasterror

Ok:       True

ErrorMsg: 

Request:  { "getlasterror" : 1 }

Response: { "err" : "BSONObj size: 0 (0x00000000) is invalid. Size must be between 0 and 16793600(16MB) First element: EOO", "code" : 10334, "n" : 0, "connectionId" : 37, "ok" : 1.0 }



在建索引时遇到这个问题,估计是索引文件有问题,而且只有一个集合会出现这样报错。

找到两个方法解决问题

1、可以运行mongodb修复功能解决问题,但是修复功能运行太费时间,

2、使用db.mycollecttion.find().forEach(function(x){db.mycollecttion2.insert(x)})命令,把数据拷到另一个集合mycollecttion2,删除mycollecttion

再db.mycollecttion2.find().forEach(function(x){db.mycollecttion.insert(x)})把数据拷回集合mycollecttion,重新建索引

数据量大概50万,用这命令基本是瞬间拷完,比用修复功能更快速的解决了问题。



你可能感兴趣的:(mongodb,索引)