Wilton
unread,May 2, 2011, 7:01:48 PM5/2/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hi All,
I'm trying to understand why two queries that *should* produce the
same results are not. It appears there is a difference in the way
Mongo treats dates.
Here are my two examples:
robotXXX:PRIMARY> db.market.find( { "tic" : "AAU" , "market" :
"AMEX" } );
{ "_id" : ObjectId("4da8eb551eeaf58bb2e0051b"), "adj_closing" : 0.28,
"adjustment" : 1, "close_date" : ISODate("2011-04-15T00:00:00Z"),
"closing" : 0.28, "high" : 0.28, "isin" : "CA03349A2002", "low" :
0.26, "market" : "AMEX", "opening" : 0.27, "ric" : "AAU.A", "sma200" :
2.6956999999999995, "tic" : "AAU", "updated_at" :
ISODate("2011-04-19T00:18:56.658Z"), "volume" : 76100 }
Note this query returns a record with the close_date = 2011-04-15.
However, if I run a query that specifies a date range, it fails:
robotXXX:PRIMARY> db.market.find( { "tic" : "AAU" , "market" :
"AMEX" , "close_date" : "2011-04-15T00:00:00Z"} );
robotXXX:PRIMARY>
This same query, with ISODate, returns a result:
robotXXX:PRIMARY> db.market.find( { "tic" : "AAU" , "market" :
"AMEX" , "close_date" : ISODate("2011-04-15T00:00:00Z")} );
{ "_id" : ObjectId("4da8eb551eeaf58bb2e0051b"), "adj_closing" : 0.28,
"adjustment" : 1, "close_date" : ISODate("2011-04-15T00:00:00Z"),
"closing" : 0.28, "high" : 0.28, "isin" : "CA03349A2002", "low" :
0.26, "market" : "AMEX", "opening" : 0.27, "ric" : "AAU.A", "sma200" :
2.6956999999999995, "tic" : "AAU", "updated_at" :
ISODate("2011-04-19T00:18:56.658Z"), "volume" : 76100 }
Can somebody please explain this difference? The problem is I'm using
the Java Mongo driver, which is *not* using the ISODate() format for
the queries, so I'm getting incorrect results in a lot of cases.