mongodb-labs / mongo-csharp-search

C# driver extension providing support for Atlas Search
Apache License 2.0
17 stars 1 forks source link

Why the Range operator won't work with one bound? #16

Open LarryZhou opened 2 years ago

LarryZhou commented 2 years ago

I'm trying to do a search on a DateTime field that's earlier than a defined value (like 01/01/2020), using RangeDateTime(). But for the sytax to work, I was forced to provide both Lt() and Gt(), which is unnecessary. In fact, the Atlas Range operator requires only one bound (see an official example here), i.e., providing either the lower or upper is sufficient.

I believe having one bound will also solve another of my problems, which occurs when the DateTime field's value is null. To get the null value document,

SearchBuilders<Entity>.Search.RangeDateTime(x => x.DeletionDate).Lt(DateTime.MinValue) Note: null is less than 1 base on the mongosh output: null < 1 (true)

Is there is way to use RangeDateTime with only one bound?

Thx.

dgolub commented 2 years ago

This was an oversight in building the driver extension. I'll look into adding this feature in a subsequent version. (1.1.0 is largely finalized at this point, so it will probably be in 1.1.1 or 1.2.0.)