I'm trying to query a mongodb based on timestamp, but I always seem to get an empty list back. I must be formatting something wrong. For the mongo document below:
{
"_id" : ObjectId("21def16043fe370208f857c2"),
"username" : "user",
"domain" : "domain.com",
"hash" : "65fdacac5ff9e",
"created" : ISODate("2012-11-20T16:08:28Z"),
"ip" : "160.85.11.222",
"actions" :
...
}
I want to filter documents by the created field. However, when I try use :
mongo <- mongo.create()
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.start.object(buf, "created")
mongo.bson.buffer.append(buf, "$gt", "2013-01-01")
mongo.bson.buffer.finish.object(buf)
mongo.bson.buffer.append(buf, "$lt", "2013-08-01")
mongo.bson.buffer.finish.object(buf)
query <- mongo.bson.from.buffer(buf)
cursor <- mongo.find(mongo, "domain.actions", query)
I get a empty list. When I just use $gt or $lt it doesn't work either. Is the date formatted wrong? Or is the query wrong?
Looks like rmongodb has had an update on this issue. From the rmongodb website:
I changed the originally quoted
MSK
timezone toGMT
to make it work on my data.