I wanted to use example from this answer, but it throws:
LiteDB.LiteException
HResult=0x80131500
Message=Invalid BSON data type 'Null' on field '_id'.
Source=LiteDB
I thought that LiteDB will auto-generate '_id'. I don't mind it. In this example there is no '_id' in BsonDocument, so I assume it is somehow auto-generated.
Any clues?
Edit:
I now see that this feature is removed from LiteDB 4.0. So how could I substitute it?
Hi @qqgg231, thanks! It麓s a bug, need work (AutoId was removed in v4 custom types only). I'm fixing...
Btw what do you mean by custom types? POCO classes or something else? BsonDocument is not custom?
Custom types for used in Id property (like create autoid for string Id).
I just commit to fixed this.
Thank you :-)
There is no more auto index creation.
https://github.com/mbdavid/LiteDB/wiki/Indexes#changes-in-v4
So should this be changed like that ?
There is no more auto index creation for custom types. Nothing changes if you don't use custom types indexes.
Hi @qqgg231, "auto index" is not the same "auto id".
Auto index is create an index based on query execution (when you just run a query and database create an index if need). This feature was removed because now LiteDB supports full scan search too (search with no index).
Auto Id is like "Auto Increment" in sql server. This was removed in LiteDatabase level (any POCO class) and was implemented in LiteEngine level (BsonDocument only).
(sometimes is not too clear for anyone but me 馃槃)
Thank you for explanation :smirk:
I added some wiki content about this
So what's the status on this?
I am getting the _id Null error with LiteDatabase as well as LiteRepository.
I don't really want to use LiteEngine because it doesn't integrate object mapping.
Any other way to use auto id?
Oh, I found the reason:
https://github.com/mbdavid/LiteDB/blob/0bf2c327e2ebb91c5b8448c77df1652b921c81d2/LiteDB.Tests/Database/AutoId_Tests.cs#L82
I changed my Id property from string to Guid now and it's working :D
Hi @FelschR, now only possible AutoId types are implemented. If you want use string data type you need set your _id
Created seperate issue for this: https://github.com/mbdavid/LiteDB/issues/1117
How 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?
```c#
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" });
}
}
}
```
Most helpful comment
Hi @qqgg231, "auto index" is not the same "auto id".
Auto index is create an index based on query execution (when you just run a query and database create an index if need). This feature was removed because now LiteDB supports full scan search too (search with no index).
Auto Id is like "Auto Increment" in sql server. This was removed in
LiteDatabaselevel (any POCO class) and was implemented inLiteEnginelevel (BsonDocument only).(sometimes is not too clear for anyone but me 馃槃)