Details
-
Bug
-
Resolution: Works as Designed
-
Major - P3
-
None
-
2.9.3
-
None
Description
Model
public class MyClass |
{
|
public ObjectId Id { get; set; } |
|
public bool MyBoolean { get; set; } |
public string Name { get; set; } |
}
|
Filter with expression
var filter = Collection.Find(x => !x.MyBoolean)
|
// filter.ToString() |
converts into
{
|
"MyBoolean": { $ne: true} |
}
|
but should converts into
{ "MyBoolean": false } |
cause its boolean and it is not ignored (can't be `BsonNull`).
It's important in cases where you want to use sort by index and had compound index with "MyBoolean" in it.
So now if you had index like {MyBoolean: 1, Name: 1} this query can't use it:
Collection.Find(x => !x.MyBoolean).SortBy(x => x.Name)
|
because of filter {"MyBoolean":{$ne:true}} and you have to write it like this:
Collection.Find(x => x.MyBoolean == false).SortBy(x => x.Name) |
to get filter
{ "MyBoolean": false }and achieve sorting by index.