[JAVA-1723] JsonReader throws exception with some valid Shell Mode ISODate constructores Created: 26/Mar/15  Updated: 26/Mar/15  Resolved: 26/Mar/15

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

For example:

{
   d :  {
            $gte : ISODate('2015-03-19 16:00:12.000Z'), 
            $lt : ISODate('2015-03-19 16:00:30.000Z')
        }
}

fails to parse.



 Comments   
Comment by Alex Paransky [ 26/Mar/15 ]

Not sure if this is related, however:

This query produces results:

mongoTemplate
    .getDb()
    .getCollection("events")
    .count(
        BasicDBObjectBuilder
            .start(
                "d",
                BasicDBObjectBuilder
                    .start()
                    .add("$gte", ISODateTimeFormat.dateTime().parseDateTime("2015-03-19T09:00:00.000-07:00").toDate())
                    .add("$lt", ISODateTimeFormat.dateTime().parseDateTime("2015-03-19T09:00:01.000-07:00").toDate())
                    .get()
            )
            .get()
    );

However, this query fails:

mongoTemplate
    .getDb()
    .getCollection("events")
    .count(
        (DBObject)
            JSON.parse(
                "{ \"d\" : { \"$gte\" : { \"$date\" : \"2015-03-19T09:00:00.000-07:00\" }, \"$lt\" : { \"$date\" : \"2015-03-19T09:00:01.000-07:00\" } } }"
            )
    );

Also this query fails:

mongoTemplate
    .getDb()
    .getCollection("events")
    .count(
        (DBObject)
            JSON.parse(
                "{ \"d\" : { \"$gte\" : { \"$date\" : \"2015-03-19T16:00:00.000+00:00\" }, \"$lt\" : { \"$date\" : \"2015-03-19T16:00:01.000+00:00\" } } }"
            )
    );

Although all of

2015-03-19T16:00:00.000+00:00

2015-03-19T09:00:00.000-07:00

2015-03-19T16:00:00.000Z

Should be equivalent.

To make the broken query work requires the date format with the Z at the end:

This works:

mongoTemplate
    .getDb()
    .getCollection("events")
    .count(
        (DBObject)
            JSON.parse(
                "{ \"d\" : { \"$gte\" : { \"$date\" : \"2015-03-19T16:00:00.000Z\" }, \"$lt\" : { \"$date\" : \"2015-03-19T16:00:01.000Z\" } } }"
            )
    );

These behaviors were consistent/same between the 3.0.0 rc1 and 2.13.0 drivers.

I believe, queries that fail to return results should be working identically to those that actually return results in this example.

Comment by Jeffrey Yemin [ 26/Mar/15 ]

The shell accepts ISODate without the 'T' between the date and the time parts, but that's not what's documented on http://docs.mongodb.org/manual/reference/mongodb-extended-json/.

Comment by Jeffrey Yemin [ 26/Mar/15 ]

The date format should be this instead:

{ 'd' : {
          '$gt' : ISODate('2015-03-19T16:00:00.000Z'), 
          '$lt' : ISODate('2015-03-19T16:00:01.000Z') 
         } 
}

Generated at Thu Feb 08 08:55:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.