Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] v4 -> v5 Upgrade LiteDB.LiteException: Cannot insert duplicate key in unique index '_id' #1740

Closed
NongBenz opened this issue Jul 2, 2020 · 2 comments
Labels

Comments

@NongBenz
Copy link

NongBenz commented Jul 2, 2020

Version
Latest Master branch 5.0.8 (abe624)

Describe the bug
Trying to Upgrade v4 DB to v5 (loading with Connection String: "Upgrade=true;")
V4 Database hosted on Google Drive (25MB):
https://drive.google.com/file/d/13kP-boXDHsfJ9WP6IBx-LMpFdPUv7zMk/view?usp=sharing

Get Exception on new LiteDatabase(connectionString);
LiteDB.LiteException: Cannot insert duplicate key in unique index '_id'. The duplicate value is '"azAZ09"'.

Code to Reproduce
new LiteDatabase("Upgrade=true; Filename=usersv4.db;");

Expected behavior
I was really hoping for a smooth upgrade from v4 to v5 databases since I work in a production environment.

Screenshots/Stacktrace

[DB] Load error: LiteDB.LiteException: Cannot insert duplicate key in unique index '_id'. The duplicate value is 'azAZ09'.
  at LiteDB.Engine.IndexService.AddNode (LiteDB.Engine.CollectionIndex index, LiteDB.BsonValue key, LiteDB.Engine.PageAddress dataBlock, System.Byte level, LiteDB.Engine.IndexNode last) [0x00128] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.Engine.IndexService.AddNode (LiteDB.Engine.CollectionIndex index, LiteDB.BsonValue key, LiteDB.Engine.PageAddress dataBlock, LiteDB.Engine.IndexNode last) [0x00055] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x000f3] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.Engine.LiteEngine.RebuildContent (LiteDB.Engine.IFileReader reader) [0x00130] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.Engine.LiteEngine.Upgrade (System.String filename, System.String password) [0x00133] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.LiteDatabase..ctor (LiteDB.ConnectionString connectionString, LiteDB.BsonMapper mapper) [0x00039] in <b80fc713aed144279006f0797bd35ed4>:0 
  at LiteDB.LiteDatabase..ctor (System.String connectionString, LiteDB.BsonMapper mapper) [0x00007] in <b80fc713aed144279006f0797bd35ed4>:0 
  at BrokeProtocol.Server.LiteDB.Driver.CJCEPPOGFEG () [0x0001c] in <69fa3b45e17a42a98d5e2c6a47ea61ef>:0
@lbnascimento
Copy link
Contributor

@NongBenz This issue is happening because there is an user with id azAZ09 and another one with id azaz09, and LiteDB uses CompareOptions.IgnoreCase by default. If you checkout the latest master and add Collation=en-US/None; to your connection string, you should be able to upgrade your datafile.

@NongBenz
Copy link
Author

NongBenz commented Jul 2, 2020

Excellent. I'll try it out. Big thanks.

@NongBenz NongBenz closed this as completed Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants