question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to auto-generate _id?

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mbdavidcommented, Nov 8, 2017

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 😄)

1reaction
felschrcommented, Jan 19, 2018

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 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to auto generate id [duplicate]
Create an ID column in your database (I am guessing you are using MS SQL because you stated only C#). · Set Identity...
Read more >
Returning an Auto-Generated Id with JPA
In this tutorial, we'll discuss how we can handle auto-generated ids with JPA.
Read more >
AUTO GENERATING AN ID IN ASP.NET - YouTube
In this video, we'll be demonstrating how to generate a unique auto generated id using SQL Server. This id can be used to...
Read more >
i want to auto generate id in the format IDA201912000001
In other way, and probably the best, is to store this number in a table of "counters" and increment that number.
Read more >
Solved: Auto generate ID Number - Power Platform Community
Solved: Hi I am new to Power Apps How to autogenerate ID number in power apps form and save that in SharePoint list....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found