summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2014-05-01 17:31:24 -0400
committerDan Pasette <dan@mongodb.com>2014-05-15 17:32:20 -0400
commit28bab1646931c346ff2e0fbc036ae4935d8c31b8 (patch)
tree5790be65fc144c62d50c77b602a43214039eac7b /jstests
parent8ff445004bda16b05fcdc15d9276578e73e5f66d (diff)
downloadmongo-28bab1646931c346ff2e0fbc036ae4935d8c31b8.tar.gz
SERVER-13769 QueryPlanner::plan() has to clear tags from query tree
(cherry picked from commit 8d48e785906d31dda3107a4a5a74ef940b4f2c89)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/geo_distinct.js58
1 files changed, 58 insertions, 0 deletions
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 ] );