litedb-org / LiteDB

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

[QUESTION] Unset a a property #2531

Open ssteiner opened 3 months ago

ssteiner commented 3 months ago

I'm implementing Migrations for LiteDb. In other NoSql Dbs, they have an unset command, which allows you to clear a property from a document (or a set of documents). Is there something similar with LiteDb?

I know I can load all documents from a collection, call BsonDocument.Remove(propertyName) to remove a property, then call collection.Update(doc) - but that requires loading every document. To add a property / set a property, I can use the collection.UpdateMany method with a BsonDocument containing the changes I want to make, so no need to load everything. Is there something like that to remove a property from a list of documents without having to load them all?

JKamsker commented 3 months ago

I strongly believe that behind the scenes, every document is loaded when calling UpdateMany anyways.

ssteiner commented 3 months ago

Hmm... I guess I'll have a look. I already tried a local build yesterday when I couldn't run DropCollection with an active transaction.