[SERVER-10071] Timestamp comparisons work inconsistently and queries seem to return incorrect results. Created: 01/Jul/13  Updated: 10/Dec/14  Resolved: 01/Jul/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.4, 2.5.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Shaun Verch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Depending on whether the shell saves ts as

{t: xxx, i: x}

or Timestamp(xxx,x) different queries return different results even though they appear the same in the shell.

test@(2.5.0) > db.querytest.insert({ts:Timestamp(1371589951, 5)})
Inserted 1 record(s) in 310ms
test@(2.5.0) > db.querytest.insert({ts:{ "t" : 1371589951, "i" : 5 }})
Inserted 1 record(s) in 1ms
test@(2.5.0) > db.querytest.find({ts: { "$gte" : Timestamp(1371589951, 1), "$lte" : Timestamp(1371589952 , 1) } } )
{ "_id" : ObjectId("51d1bbbffce6ce6f1f87fb4e"), "ts" : Timestamp(1371589951, 5) }
Fetched 1 record(s) in 3ms
test@(2.5.0) > db.querytest.find({ts: { "$gte" : {t: 1371589951, i: 1}, "$lte" : {t: 1371589952 , i: 1} } } )
{ "_id" : ObjectId("51d1bbc6fce6ce6f1f87fb4f"), "ts" : { "t" : 1371589951, "i" : 5 } }
test@(2.5.0) > db.querytest.find()
{ "_id" : ObjectId("51d1bbbffce6ce6f1f87fb4e"), "ts" : Timestamp(1371589951, 5) }
{ "_id" : ObjectId("51d1bbc6fce6ce6f1f87fb4f"), "ts" : { "t" : 1371589951, "i" : 5 } }
Fetched 2 record(s) in 0ms

Behaves the same in 2.5.0 and 2.4.4



 Comments   
Comment by Shaun Verch [ 01/Jul/13 ]

Closing as works as designed since timestamps need to use the "extended json" representation: http://docs.mongodb.org/manual/reference/mongodb-extended-json/.

Generated at Thu Feb 08 03:22:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.