[BUG] NullReferenceException on Insert with auto id and BsonDocument with `_id=0`
See original GitHub issueNullReferenceException on Insert with auto id and BsonDocument with _id=0
Version
LiteDB 5.0.2 and the latest from repo, Windows 10, net45
Describe the bug
- Given a
LiteCollection<BsonDocument>
with auto idInt32
. - Insert a
BsonDocument
with_id = 0
. - -> NullReferenceException
Code to Reproduce
using (var db = new LiteDatabase(":memory:"))
{
var test = db.GetCollection("Test", BsonAutoId.Int32);
var doc = new BsonDocument() { ["_id"] = 0, ["p1"] = 1 };
test.Insert(doc); // -> NullReferenceException
}
Expected behavior
This scenario works without exceptions and maybe sets the _id
in the input document to the generated value.
But if for some reason this scenario is not valid then the exception should be different, some clear error.
Stack
> LiteDB.dll!LiteDB.LiteCollection<LiteDB.BsonDocument>.Insert(LiteDB.BsonDocument entity) Line 27 C#
MyLiteDB.exe!TryLiteDB.Program.Main(string[] args) Line 17 C#
Failed code due to null _id
:
// checks if must update _id value in entity
if (removed)
{
_id.Setter(entity, id.RawValue);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
MongoDB id remains null after InsertOneAsync
But when creating a new instance of the derived class and using InsertOneAsync to add it to my collection, the document is added...
Read more >C# Driver updating BsonDocument
Hello i got an issue with MongoDB model builder like example i have UserModel for adding or updating existing document in mongo
Read more >litedb insert的推薦與評價,GITHUB - 最新趨勢觀測站
Version LiteDB v5.0.10 .NET Standard 2.1 Xamarin.Forms v5.0.0.2012. Describe the bug The database seems to get corrupted when I insert data. ... <看更多> ......
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
I will back into this issue before new release
Thanks again @nightroman, this 3th-party fine tests are great for LiteDB