[BUG] Can't empty collection with DeleteMany()
See original GitHub issueVersion 5.0.3 on .NET CORE 3.1
Describe the bug I’m trying to empty my collection (all data should be removed). When trying to call the DeleteMany() it fails. I get an error (see stacktrace).
Code to Reproduce
using (var database = new LiteDatabase($"FileName=data.db"))
{
var collection = database.GetCollection<Photo>();
collection.DeleteMany(_ => true);
}
Expected behavior Collection should be made empty
Screenshots/Stacktrace
LiteDB.LiteException: Expression '@p0' are not supported as predicate expression.
at LiteDB.Engine.QueryOptimization.<SplitWherePredicateInTerms>g__add|7_0(BsonExpression predicate)
at LiteDB.Engine.QueryOptimization.SplitWherePredicateInTerms()
at LiteDB.Engine.QueryOptimization.ProcessQuery()
at LiteDB.Engine.QueryExecutor.<>c__DisplayClass10_0.<<ExecuteQuery>g__RunQuery|0>d.MoveNext()
at LiteDB.BsonDataReader..ctor(IEnumerable`1 values, String collection)
at LiteDB.Engine.QueryExecutor.ExecuteQuery(Boolean executionPlan)
at LiteDB.Engine.QueryExecutor.ExecuteQuery()
at LiteDB.Engine.LiteEngine.Query(String collection, Query query)
at LiteDB.Engine.LiteEngine.<>c__DisplayClass4_0.<<DeleteMany>g__getIds|1>d.MoveNext()
at LiteDB.Engine.LiteEngine.<>c__DisplayClass3_0.<Delete>b__0(TransactionService transaction)
at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
at LiteDB.Engine.LiteEngine.Delete(String collection, IEnumerable`1 ids)
at LiteDB.Engine.LiteEngine.<>c__DisplayClass4_0.<DeleteMany>b__0(TransactionService transaction)
at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
at LiteDB.Engine.LiteEngine.DeleteMany(String collection, BsonExpression predicate)
at LiteDB.LiteCollection`1.DeleteMany(BsonExpression predicate)
at LiteDB.LiteCollection`1.DeleteMany(Expression`1 predicate)
Additional context I also tried it with the following code without any success:
using (var database = Context.CreateDatabaseContext())
{
var collection = database.GetCollection<Movie>();
collection.DeleteMany(Query.All().Select);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
node.js - deleteMany() in mongodb not deleting documents
1 Answer. According to the documentation, deleteMany expects filter query as the first argument. In your case, since the first argument does ...
Read more >deleteMany : delete large number of documents not working
While deleting using deleteMany(), documents are not deleting from the collection. Is there any limit for deleteMany opertion?
Read more >Stuck on "Delete Many Documents with model.remove ...
I see this error in the response in the network tab (browser dev tools). E11000 duplicate key error collection: fcc_challange.people index: ...
Read more >Cannot delete this collection as it is used in bindings - CMS ...
I am trying to delete two empty collection so I can remove the CMS entirely from one of the sites I'm working on....
Read more >Delete data from Cloud Firestore - Firebase
The following examples demonstrate how to delete documents, fields, and collections.
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
Hi @mregni,
This has been fixed in commit ed9382cd5a839169bbe636cd0166e45100a7c717, but it isn’t available yet in v5.0.3.
You can use this is a work-around for now though 🙂
collection.DeleteMany("1=1");
Assuming that this answers your question (for now), I’ll close this issue. If you feel like my answer is incomplete, or not completely answering your question, feel free to re-open it.
Hi @mregni, just wanted to inform you that v5.0.4 has been released (which includes the fix for your issue)