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);
}
Looks a lot like #1478, @JensSchadron mentions it should work in the last comment.
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.
@JensSchadron, Thanks for the tip!
I think you made a typo there, I presume you mean collection.DeleteMany("1=1");
@mregni My bad, you're right about the typo :sweat_smile:
I'll correct it in my previous response
Hi @mregni, just wanted to inform you that v5.0.4 has been released (which includes the fix for your issue)
Most helpful comment
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.