Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

$gt query behaves as $gte for timestamps with millisecond precision. #3747

Open
robj opened this Issue · 2 comments

2 participants

@robj

In an empty db, 1 Video is created

2.1.0 :010 > float_created_at = Video.first.created_at.to_f
1406102520.972
2.1.0 :012 > Video.where(:created_at.gte => float_created_at).count
1
2.1.0 :011 > Video.where(:created_at.gt => float_created_at).count
1

$gt should be 0, not 1

This is important for example when using timestamps for pagination, where millisecond precision is necessary (ie. multiple Posts might have been created on the same second).

Similarly $lte , in the following case should return 1, not 0

2.1.0 :014 > Video.where(:created_at.lt => float_created_at).count
0
2.1.0 :015 > Video.where(:created_at.lte => float_created_at).count
0

@robj

I have tested the same query in the mongo shell, and the results came back as I would expect, so this looks to be a Mongoid bug.

> db.videos.count()
1
created_at_isodate  = db.videos.find()[0]['created_at']
> db.videos.find( { created_at: { $gt: created_at_isodate  }  }).count()
0
> db.videos.find( { created_at: { $gte: created_at_isodate  }  }).count()
1
@xixilive

I made a query with like:

Dione::Admin.gt(current_sign_in_at: 1408412359.136).count

and, mongosniff output followings:

127.0.0.1:55333  -->> 127.0.0.1:27017 admin.$cmd  58 bytes  id:1b   27
    query: { ismaster: 1 }  ntoreturn: -1 ntoskip: 0
127.0.0.1:27017  <<--  127.0.0.1:55333   194 bytes  id:117648   1144392 - 27
    reply n:1 cursorId: 0
    { ismaster: true, maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1408513847235), maxWireVersion: 2, minWireVersion: 0, ok: 1.0 }
127.0.0.1:55333  -->> 127.0.0.1:27017 dione_development.$cmd  130 bytes  id:1c  28
    query: { count: "dione_admins", query: { current_sign_in_at: { $gt: new Date(1408412359135) } } }  ntoreturn: -1 ntoskip: 0
127.0.0.1:27017  <<--  127.0.0.1:55333   64 bytes  id:117649    1144393 - 28
    reply n:1 cursorId: 0
    { n: 2.0, ok: 1.0 }

Mongoid version: 4.0
MongoDB version: 2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.