mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.52k stars 1.24k forks source link

[BUG] Document not found on update #2407

Closed FCUnlimited closed 8 months ago

FCUnlimited commented 8 months ago

Version 5.0.17

Describe the bug I can read all data but it is not possible to change values. If I try to change a value LiteDB Studio tells me that the document was not found. I followed the source code until IndexService.Find. It looks like it is not checking each value.

Code to Reproduce It does also not work with the LiteDB Studio. So please try to update a field in the attached db.

Expected behavior The value should get updated / the document should be found

Screenshots/Stacktrace The document is not found when using ILiteCollection.Update (returns false)

UpdateDocumentNotFound.zip

Thank you very much!

FCUnlimited commented 8 months ago

so it looks like somehow the _id is broken - have no idea what exactly but the IndexService is not able to find the document. If I use UpdateMany I can update the document. It searches via a query and not as smart as the IndexService.

Sadly the IndexService.Find method is quiet complicated for me :/

FCUnlimited commented 8 months ago

Found a solution - not really the problem but a solution: I used the LiteEngine.Update method. Which calls the TransactionService.CreateSnapshot different than the Upsert method. The Upsert method set the parameter "addIfNotExists" to true the UpDate method not.

Now I just use the Upsert method which does an update and not a reset - I tested.