-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.4.0
-
Component/s: Querying
-
None
-
Environment:Linux 32 bit
Using limit() and skip() to page result sets yields unexpected results when utilizing geospatial querying and an additional sort key. Objects are not correctly sorted per the additional sort key, and some of the same objects appear in subsequent result sets.
To reproduce:
use foo db.foo.ensureIndex({loc: "2d"}) db.foo.ensureIndex({random: 1 }) for( var i = 1; i <= 100; i++ ){db.foo.save( { loc: [1, 1], random: Math.floor(Math.random()*100) } )} /* query 5 objects per set */ /* page 1 */ db.foo.find({loc: {$near: [1, 1]}}).limit(5).skip((1 - 1) * 5).sort({random: 1}) { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931c"), "loc" : [ 1, 1 ], "random" : 40 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931e"), "loc" : [ 1, 1 ], "random" : 55 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931f"), "loc" : [ 1, 1 ], "random" : 63 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931b"), "loc" : [ 1, 1 ], "random" : 71 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931d"), "loc" : [ 1, 1 ], "random" : 75 } /* page 2 */ db.foo.find({loc: {$near: [1, 1]}}).limit(5).skip((2 - 1) * 5).sort({random: 1}) { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931f"), "loc" : [ 1, 1 ], "random" : 63 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad9324"), "loc" : [ 1, 1 ], "random" : 67 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931b"), "loc" : [ 1, 1 ], "random" : 71 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931d"), "loc" : [ 1, 1 ], "random" : 75 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad9322"), "loc" : [ 1, 1 ], "random" : 99 } /* page 3 */ db.foo.find({loc: {$near: [1, 1]}}).limit(5).skip((3 - 1) * 5).sort({random: 1}) { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad9324"), "loc" : [ 1, 1 ], "random" : 67 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931b"), "loc" : [ 1, 1 ], "random" : 71 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad931d"), "loc" : [ 1, 1 ], "random" : 75 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad9328"), "loc" : [ 1, 1 ], "random" : 91 } { "_id" : ObjectId("4bb2d5e2284b5ab1d9ad9322"), "loc" : [ 1, 1 ], "random" : 99 }
- related to
-
SERVER-2997 limits do not seem to work correctly in shell when count()'ing $near queries
- Closed