dselivanov / rmongodb

R driver for MongoDB
53 stars 26 forks source link

missing milliseconds in timestamp while querying with mongo.find.all #89

Open annkochepasova opened 8 years ago

annkochepasova commented 8 years ago

When I switch from working with mongo cursors (mongo.find) to fetching data frames (mongo.find.all) I get a data frame with POSIXct timestamps and those timestamps don't have milliseconds.

E.x:


res = mongo.find.all(...)

tsval = as.numeric(res$timestamp[1])

print(tsval, digits=20) 
# prints 1429294389
cursor = mongo.find(...)

tsval = as.numeric(mongo.bson.value(mongo.cursor.value(cursor), 'timestamp'))

print(tsval, digits=20) 
# prints 1429294389.1229999

Expected behaviour: Should receive the same result with milliseconds in both cases - 1429294389.1229999

dselivanov commented 8 years ago

Please, provide fully reproducible example, so I will be able to investigate into this.

rghermi commented 8 years ago

Hi, I'm having the same issue. When fetching a document from mongoDB using mongo.find.all() the milliseconds of the date are not retrieved. For ex. Inser a document into mongoDB:

db.textos.insert({_id: new Date(), fichero : "Cocina para todos.pdf",tipo : "pdf", contenido :"lorem ipsum cocina para todos",meta:"title: cocina facil  : Alberto Chicote", userId : "UserId2", palabras : 55322, status : "new"})

This is the outcome in mongoDB shell:

{ "_id" : ISODate("2016-06-20T10:04:35.389Z"), "fichero" : "Cocina para todos.pdf", "tipo" : "pdf", "contenido" : "lorem ipsum cocina para todos", "meta" : "title: cocina facil : Alberto Chicote", "us erId" : "UserId2", "palabras" : 55322, "status" : "new" }

The _id is a date format.

From my R script

buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "tipo", "pdf")
query <- mongo.bson.from.buffer(buf)
inputTest <- mongo.find.all(mongo,DBNS,query)

inputTest is a list. This is how the _id is stored in the R list inputTest:

[[2]]$_id [1] "2016-06-20 12:05:26 CEST"

The milliseconds are missing.

I hope I have provided the evidence to start an investigation.

rghermi commented 8 years ago

Hi, just a note to the comment above, I'm using rmongodb v 1.8.0

packageVersion("rmongodb") [1] ‘1.8.0’

rghermi commented 8 years ago

Hi, also specifying the format with 3 milliseconds like:

format(inputTest[[1]]$"_id", "%Y-%m-%d %H:%M:%OS3")

the outcome is:

"2016-06-18 19:11:07.000"