How to compare dates in BSON ReactiveMongo query?

I am using ReactiveMongo without fremework download.

I'm trying to write the equivalent of the following simple MongoDB query:

db.oplog.rs.find({"o.TimeCreated":{"$gt": ISODate("2014-09-30T10:00:00.000Z")}})

      

I've tried things like:

val query = BSONDocument(
        "o.TimeCreated" -> BSONDocument("$gt" -> BSONDateTime(ts))) // ts is the timestamp corresponding to the date "2014-09-30T10:00:00.000Z"

      

hoping that the "$ gt" operator will work for comparing two BSONDateTime objects, assuming the "o.TimeCreated" value will be internally represented as a BSONDateTime object.

But I can't figure out how to get the request to work (no data is returned).

Any suggestions? Thank!

+3


source to share


1 answer


I can offer several options for you:



  • You might want to try BSONTimestamp instead of BSONDateTime in your request
  • Do the documents in the oplog.rs collection have a top-level object named "o.TimeCreated"?
  • Is there an object in the collection that can satisfy the request with the timestamp you are using?
0


source







All Articles