LiteDB.LiteException: 'Cannot insert duplicate key in unique index '_id'
See original GitHub issueHow come that i get a LiteDB.LiteException: 'Cannot insert duplicate key in unique index '_id'. The duplicate value is '0'.'
with the following code?
It looks like the AutoId doesn’t work in this scenario, or am i missing something?
public class Test {
public int id { get; set; }
public string text { get; set; }
}
static class Program
{
static void Main()
{
using (var db = new LiteDatabase("database.db")) {
LiteCollection<object> collection = db.GetCollection<object>("testCollection");
collection.Insert(new Test { text = "aaa" });
collection.Insert(new Test { text = "bbb" });
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
LiteDB.LiteException: 'Cannot insert duplicate key in ...
Insert(T document) started throwing the cited exception: LiteDB.LiteException: 'Cannot insert duplicate key in unique index '_id'. The duplicate ...
Read more >LiteDB - Multiple entries with same ID
I want to be able to insert warnings with the same UserId , like in SQLite, but I get this error: Cannot insert...
Read more >Service crash randomly
LiteException : Cannot insert duplicate key in unique index '_id'. The duplicate value is '"$/dashboardlog/17\00001"'. at LiteDB.IndexService.
Read more >Developing a standalone embystat server - Page 25
LiteException: Cannot insert duplicate key in unique index '_id'. The duplicate value is '453207'. at LiteDB.IndexService.AddNode(CollectionIndex index ...
Read more >Cannot insert duplicate key row in object 'dbo.Items' with ...
System.Exception: Cannot insert duplicate key row in object 'dbo.Items' with unique index 'ndxID'. The duplicate key value is ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes your types have an ID property but object does not. LiteDb uses the type given to the getcollection function to know what properties should be used. In your case you have passed object. As I said look into use generics or the dynamic keyword for this
Happy to help!