Using Firedac For MongoDB's Time Range Query

239 Views Asked by At

I has one question about time range query.

Here is my code:

TMongoPipeline*  MGPipeline = new TMongoPipeline(FEnv);
MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:ISODate(\"2000-11-02T17:04:11.102Z\")}}";                           ^^^^^^^^^                                                                                          

where DayTime field's Data type is Date

Compile is ok, but it always throw an exception as like this:

project TestC.cpp raised exception class EJSONReaderException with message 'Cannot read Infinity value' Path 'DayTime', line 1, position 9'.

I also tried another code:

TMongoPipeline*  MGPipeline = new TMongoPipeline(FEnv);
MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:new Date(2001,1,1)}}";
                                                ^^^^^^^^^                                                                                          

But it throw exception,too.

TestC.cpp raised exception class $C0000094 with message 'integer divide by zero at 0x50096'

My MongoDB version is 3.0.

Now I can't do any time range query.

Can tell me anyway to do that by using FireDac and Rad Studio XE10?

1

There are 1 best solutions below

0
da-soft On

You should use Extended JSON:

MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:{\"$date\":\"2000-11-02T17:04:11.102Z\"}}}";