From 28bab1646931c346ff2e0fbc036ae4935d8c31b8 Mon Sep 17 00:00:00 2001 From: Jason Rassi Date: Thu, 1 May 2014 17:31:24 -0400 Subject: SERVER-13769 QueryPlanner::plan() has to clear tags from query tree (cherry picked from commit 8d48e785906d31dda3107a4a5a74ef940b4f2c89) --- jstests/core/geo_distinct.js | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'jstests') diff --git a/jstests/core/geo_distinct.js b/jstests/core/geo_distinct.js index b0117a2bdbb..bb2fd5bf85b 100644 --- a/jstests/core/geo_distinct.js +++ b/jstests/core/geo_distinct.js @@ -1,5 +1,6 @@ // Tests distinct with geospatial field values. // 1. Test distinct with geo values for 'key' (SERVER-2135) +// 2. Test distinct with geo predicates for 'query' (SERVER-13769) var coll = db.geo_distinct; var res; @@ -46,3 +47,60 @@ assert.commandWorked( coll.ensureIndex( { 'loc.coordinates': '2d' } ) ); res = coll.runCommand( 'distinct', { key: 'loc.coordinates' } ); assert.commandWorked( res ); assert.eq( res.values.sort(), [ 10, 20, 30 ] ); + +// +// 2. Test distinct with geo predicates for 'query'. +// + +coll.drop(); +for (var i=0; i<50; ++i) { + coll.insert( { zone: 1, loc: { type: 'Point', coordinates: [ -20, -20 ] } } ); + coll.insert( { zone: 2, loc: { type: 'Point', coordinates: [ -10, -10 ] } } ); + coll.insert( { zone: 3, loc: { type: 'Point', coordinates: [ 0, 0 ] } } ); + coll.insert( { zone: 4, loc: { type: 'Point', coordinates: [ 10, 10 ] } } ); + coll.insert( { zone: 5, loc: { type: 'Point', coordinates: [ 20, 20 ] } } ); +} +var originGeoJSON = { type: 'Point', coordinates: [ 0, 0 ] }; + +// Test distinct with $nearSphere query predicate. + +// A. Unindexed key, no geo index on query predicate. +res = coll.runCommand( 'distinct', { key: 'zone', + query: { loc: { $nearSphere: { $geometry: originGeoJSON, + $maxDistance: 1 } } } } ); +assert.commandFailed( res ); +// B. Unindexed key, with 2dsphere index on query predicate. +assert.commandWorked( coll.ensureIndex( { loc: '2dsphere' } ) ); +res = coll.runCommand( 'distinct', { key: 'zone', + query: { loc: { $nearSphere: { $geometry: originGeoJSON, + $maxDistance: 1 } } } } ); +assert.commandWorked( res ); +assert.eq( res.values.sort(), [ 3 ] ); +// C. Indexed key, with 2dsphere index on query predicate. +assert.commandWorked( coll.ensureIndex( { zone: 1 } ) ); +res = coll.runCommand( 'distinct', { key: 'zone', + query: { loc: { $nearSphere: { $geometry: originGeoJSON, + $maxDistance: 1 } } } } ); +assert.commandWorked( res ); +assert.eq( res.values.sort(), [ 3 ] ); + +// Test distinct with $near query predicate (recall that $near returns the closest 100 points). + +coll.dropIndexes(); + +// A. Unindexed key, no geo index on query predicate. +res = coll.runCommand( 'distinct', { key: 'zone', + query: { 'loc.coordinates': { $near: [ 0, 0 ] } } } ); +assert.commandFailed( res ); +// B. Unindexed key, with 2d index on query predicate. +assert.commandWorked( coll.ensureIndex( { 'loc.coordinates': '2d' } ) ); +res = coll.runCommand( 'distinct', { key: 'zone', + query: { 'loc.coordinates': { $near: [ 0, 0 ] } } } ); +assert.commandWorked( res ); +assert.eq( res.values.sort(), [ 2, 3, 4 ] ); +// C. Indexed key, with 2d index on query predicate. +assert.commandWorked( coll.ensureIndex( { zone: 1 } ) ); +res = coll.runCommand( 'distinct', { key: 'zone', + query: { 'loc.coordinates': { $near: [ 0, 0 ] } } } ); +assert.commandWorked( res ); +assert.eq( res.values.sort(), [ 2, 3, 4 ] ); -- cgit v1.2.1