[SERVER-8190] find() or mapreduce query with { $date: '...' } doesn't work, only ISODate('...') Created: 16/Jan/13  Updated: 16/Nov/21  Resolved: 16/Jan/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Robin Thomas Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

direct connection to both primary and secondary nodes in replica set. CentOS Unix, mongod 2.2.2.


Operating System: ALL
Participants:

 Description   

Using both Java driver 2.10.1 and the mongo shell, if I perform a find() (or a mapreduce with same initial query), if I use

{ $date: '...' }

to specify a date value, no results are found and also the query takes a long time to complete. If I use ISODate('...') (in the shell), the query completes quickly and finds results.

Shell transcript:

shard1ReplSet:PRIMARY> db.engagement_events.find({t: { $gte:

{ $date: '2013-01-16T04:00:00Z' }

} }).count()
0
shard1ReplSet:PRIMARY> db.engagement_events.find({t:

{ $gte: ISODate('2013-01-16T04:00:00Z') }

}).count()
98024

Are ISO datetime format strings no longer supported?



 Comments   
Comment by Robin Thomas [ 16/Jan/13 ]

Ok, I see how I can do this. If I do DBObject foo = com.mongodb.util.JSON.parse(commandPayload), and then DB.command(foo), the JSON.parse() will interpret

{ $date: '2013-01-16T00:00:00Z' }

correctly. I can't do this via JS shell, but I don't need to; I just need an ISO string way to define a date field in a query for a mapr/aggregate command, that the Java driver can run.

Thanks for the help!

Comment by Scott Hernandez (Inactive) [ 16/Jan/13 ]

In the javascript shell you must use the correct types; this is the same in java. Do not use $data nor any other $oid/etc json (strict) extended notation as defined here: http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON

Generated at Thu Feb 08 03:16:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.