Closed
Description
Version
5.0.8
Describe the bug
Hi.
Or I made some stupid mistake in my code and don’t understand it. Or, a comparison condition with an index is not processed correctly.
Take a look at the test below: it adds 10 elements, and then all the elements from the collection are queried in different ways. The first two tests are successful. And the last 2 for some reason fail.
Code to Reproduce
public class StateModel
{
[BsonId]
public int Id { get; set; }
}
[Fact]
public void StateTest()
{
using (var db = new LiteDatabase(":memory:"))
{
var col = db.GetCollection<StateModel>("col");
var count = 10;
var firstId = 5;
var lastId = firstId + count - 1;
for (var i = firstId; i <= lastId; i++)
{
col.Insert(new StateModel
{
Id = i
});
}
var list = col.Query().ToList();
list.Should().HaveCount(count);
list = col.Query()
.Where(x => firstId <= x.Id)
.ToList();
list.Should().HaveCount(count);
list = col.Query()
.Where(x => x.Id <= lastId)
.ToList();
list.Should().HaveCount(count);
list = col.Query()
.Where(x => firstId <= x.Id && x.Id <= lastId)
.ToList();
list.Should().HaveCount(count);
}
}
Expected behavior
Test passed.
Activity
Fixed wrong expression execution on indexed fields
lbnascimento commentedon May 14, 2020
@mikhail-khalizev This issue has been fixed in master and its fix will be present in the next incremental release.
In the meantime, make sure the indexed field is always on the left part of the expression (e.g.:
x.Id >= firstId
instead offirstId <= x.Id)
.