$lt or $lte operator does not work on date field

933 views
Skip to first unread message

Suraj Sharma

unread,
Sep 30, 2013, 5:18:10 AM9/30/13
to mongod...@googlegroups.com

I have no idea why $lt or $lte operator does not work on date field though the $gt and $gte works perfectly fine. I need to perform range query based on this field. 
Works fine: for $gt and $gte 
{ "lastUpdateOn" : { "$gt" : ISODate("2013-09-19T18:30:00Z")}

not working for $lt and $lte
{ "lastUpdateOn" : { "$lt" : ISODate("2013-09-19T18:30:00Z")}    

data exist for both queries.

I am using mongo version 2.4.5.

--
Regards,
Suraj 

Gary R

unread,
Sep 30, 2013, 12:05:16 PM9/30/13
to mongod...@googlegroups.com
Running 2.4.6 here.    Both your queries work.

Are you insert-ing and update-ing as   'lastUpdateOn':new ISODate()   ?

A db.coll.find( { lastUpdateOn: { $type:2 } } ) will show if some of the date values are strings instead of ISODates.
Or for a more broad check,  db.coll.find( { lastUpdateOn: {$not: { $type:9 } } } )

Gary R.

Asya Kamsky

unread,
Oct 1, 2013, 12:00:07 AM10/1/13
to mongodb-user
It's likely that either the data doesn't exist or your query is
somehow malformed since this works for me (and others).

Can you provide (cut-n-paste) both queries and their results (or lack
of results) - and also how do you know that there is data to be
returned to the query that gets no data back?
> --
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
>
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages