jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
286 stars 65 forks source link

Malformed DateTime strings when using iterate$json() #163

Open Jax89 opened 5 years ago

Jax89 commented 5 years ago

I observed very strange behavior when querying a simple json containing an ISODate including milliseconds using the iterate$json() method. Using iterate$one() the DateTimes are fine. Milliseconds loose leading zeros, see the output below:

connection$iterate()$json()

"{ \"Date\" : { \"$date\" : \"1998-11-07T00:00:00.123Z\" } }" "{ \"Date\" : { \"$date\" : \"1998-11-07T00:00:00. 23Z\" } }" "{ \"Date\" : { \"$date\" : \"1998-11-07T00:00:00. 23Z\" } }"

The DateTimes stored in the DB are "1998-11-07T00:00:00.123Z" "1998-11-07T00:00:00.023Z" and "1998-11-07T00:00:00.023Z"

jeroen commented 5 years ago

I can reproduce this:

m <- mongo()
m$insert("{ \"Date\" : { \"$date\" : \"1998-11-07T00:00:00.023Z\" } }")
m$iterate()$json()
jeroen commented 5 years ago

I fixed this in mongolite and also reported upstream: https://github.com/mongodb/mongo-c-driver/pull/556