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.

[BUG] Can't empty collection with DeleteMany()

See original GitHub issue

Version 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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
JensSchadroncommented, Mar 10, 2020

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.

0reactions
JensSchadroncommented, Mar 12, 2020

Hi @mregni, just wanted to inform you that v5.0.4 has been released (which includes the fix for your issue)

Read more comments on GitHub >

github_iconTop 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 >

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