mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.62k stars 1.25k forks source link

[BUG] No solution for "Cannot insert duplicate key in unique index" ? #2366

Open bncdemo opened 1 year ago

bncdemo commented 1 year ago

Hi,

Is there no solution for the error (when upgrading V4 to V5): Cannot insert duplicate key in unique index '_id'. The duplicate value is '{"$numberLong":"1126889"}'. ?

Could you add some 'ignore error' switch, or 'drop duplicated item' option?

petertiedemann commented 5 months ago

I have a similar problem when upgrading (using 5.0.20):


LiteDB.LiteException: Cannot insert duplicate key in unique index '_id'. The duplicate value is '"59803E0EF693557459A7BCA047C118F998256C06E4BF7A1C4880012FF97E47B2"'.
   at LiteDB.Engine.IndexService.AddNode(CollectionIndex index, BsonValue key, PageAddress dataBlock, Byte insertLevels, IndexNode last)
   at LiteDB.Engine.IndexService.AddNode(CollectionIndex index, BsonValue key, PageAddress dataBlock, IndexNode last)
   at LiteDB.Engine.LiteEngine.InsertDocument(Snapshot snapshot, BsonDocument doc, BsonAutoId autoId, IndexService indexer, DataService data)
   at LiteDB.Engine.LiteEngine.RebuildContent(IFileReader reader)
   at LiteDB.Engine.RebuildService.Rebuild(RebuildOptions options)
   at LiteDB.Engine.LiteEngine.Recovery(Collation collation)
   at LiteDB.Engine.LiteEngine.TryUpgrade()
   at LiteDB.Engine.LiteEngine.Open()
   at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
   at LiteDB.ConnectionString.CreateEngine()
   at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
   at LiteDB.LiteDatabase..ctor(String connectionString, BsonMapper mapper)```