Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] Byte array and query #1650

Closed
RMariowski opened this issue Apr 22, 2020 · 2 comments
Closed

[BUG] Byte array and query #1650

RMariowski opened this issue Apr 22, 2020 · 2 comments
Labels

Comments

@RMariowski
Copy link

Version
LiteDB 5.0.7
Windows 10
.NET Core 3.1

Describe the bug
Using Query() from Collection and Contains() of byte array in Where() returns wrong results.
Code below clearly shows the problem.

Code to Reproduce
https://pastebin.com/ea6xAAdF

Additional context
Using something other than byte array in Where() works perfectly for example array of ints, lists etc.

@RMariowski RMariowski added the bug label Apr 22, 2020
@lbnascimento
Copy link
Contributor

@xandev This happens because byte[] is implicitly converted to a BsonValue of type Binary, which completely breaks the comparison - this doesn't happen with int[] or short[] because they are converted to a BsonArray containing the ids as ints.

I'm not sure there's anything that could be done regarding this - I couldn't think of anything, at least.

@lbnascimento
Copy link
Contributor

@xandev I found a simple way to make your example work. A lambda expression like c => ids.Contains(c.Id) becomes ITEMS(@p0) ANY = $._id when converted to a BsonExpression, so the solution was to make the ITEMS method return every byte in the byte[] cast to int.

This fix will be present in the next incremental release.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants