summaryrefslogtreecommitdiff
path: root/jstests/core/geo_distinct.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/geo_distinct.js')
-rw-r--r--jstests/core/geo_distinct.js117
1 files changed, 60 insertions, 57 deletions
diff --git a/jstests/core/geo_distinct.js b/jstests/core/geo_distinct.js
index eccb517ed83..705bf1cc7ce 100644
--- a/jstests/core/geo_distinct.js
+++ b/jstests/core/geo_distinct.js
@@ -10,25 +10,25 @@ var res;
//
coll.drop();
-coll.insert( { loc: { type: 'Point', coordinates: [ 10, 20 ] } } );
-coll.insert( { loc: { type: 'Point', coordinates: [ 10, 20 ] } } );
-coll.insert( { loc: { type: 'Point', coordinates: [ 20, 30 ] } } );
-coll.insert( { loc: { type: 'Point', coordinates: [ 20, 30 ] } } );
-assert.eq( 4, coll.count() );
+coll.insert({loc: {type: 'Point', coordinates: [10, 20]}});
+coll.insert({loc: {type: 'Point', coordinates: [10, 20]}});
+coll.insert({loc: {type: 'Point', coordinates: [20, 30]}});
+coll.insert({loc: {type: 'Point', coordinates: [20, 30]}});
+assert.eq(4, coll.count());
// Test distinct on GeoJSON points with/without a 2dsphere index.
-res = coll.runCommand( 'distinct', { key: 'loc' } );
-assert.commandWorked( res );
-assert.eq( res.values.sort(), [ { type: 'Point', coordinates: [ 10, 20 ] },
- { type: 'Point', coordinates: [ 20, 30 ] } ] );
+res = coll.runCommand('distinct', {key: 'loc'});
+assert.commandWorked(res);
+assert.eq(res.values.sort(),
+ [{type: 'Point', coordinates: [10, 20]}, {type: 'Point', coordinates: [20, 30]}]);
-assert.commandWorked( coll.ensureIndex( { loc: '2dsphere' } ) );
+assert.commandWorked(coll.ensureIndex({loc: '2dsphere'}));
-res = coll.runCommand( 'distinct', { key: 'loc' } );
-assert.commandWorked( res );
-assert.eq( res.values.sort(), [ { type: 'Point', coordinates: [ 10, 20 ] },
- { type: 'Point', coordinates: [ 20, 30 ] } ] );
+res = coll.runCommand('distinct', {key: 'loc'});
+assert.commandWorked(res);
+assert.eq(res.values.sort(),
+ [{type: 'Point', coordinates: [10, 20]}, {type: 'Point', coordinates: [20, 30]}]);
// Test distinct on legacy points with/without a 2d index.
@@ -38,69 +38,72 @@ assert.eq( res.values.sort(), [ { type: 'Point', coordinates: [ 10, 20 ] },
coll.dropIndexes();
-res = coll.runCommand( 'distinct', { key: 'loc.coordinates' } );
-assert.commandWorked( res );
-assert.eq( res.values.sort(), [ 10, 20, 30 ] );
+res = coll.runCommand('distinct', {key: 'loc.coordinates'});
+assert.commandWorked(res);
+assert.eq(res.values.sort(), [10, 20, 30]);
-assert.commandWorked( coll.ensureIndex( { 'loc.coordinates': '2d' } ) );
+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 ] );
+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 ] } } );
+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 ] };
+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 );
+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 ] );
+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 ] );
+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.
coll.dropIndexes();
// A. Unindexed key, no geo index on query predicate.
-res = coll.runCommand( 'distinct', { key: 'zone',
- query: { 'loc.coordinates': { $near: [ 0, 0 ], $maxDistance: 1 } } } );
-assert.commandFailed( res );
+res = coll.runCommand('distinct',
+ {key: 'zone', query: {'loc.coordinates': {$near: [0, 0], $maxDistance: 1}}});
+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 ], $maxDistance: 1 } } } );
-assert.commandWorked( res );
-assert.eq( res.values.sort(), [ 3 ] );
+assert.commandWorked(coll.ensureIndex({'loc.coordinates': '2d'}));
+res = coll.runCommand('distinct',
+ {key: 'zone', query: {'loc.coordinates': {$near: [0, 0], $maxDistance: 1}}});
+assert.commandWorked(res);
+assert.eq(res.values.sort(), [3]);
// 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 ], $maxDistance: 1 } } } );
-assert.commandWorked( res );
-assert.eq( res.values.sort(), [ 3 ] );
+assert.commandWorked(coll.ensureIndex({zone: 1}));
+res = coll.runCommand('distinct',
+ {key: 'zone', query: {'loc.coordinates': {$near: [0, 0], $maxDistance: 1}}});
+assert.commandWorked(res);
+assert.eq(res.values.sort(), [3]);