Skip to content

Commit

Permalink
SERVER-13769 geo_distinct.js: rewrite, add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassi committed May 1, 2014
1 parent 27c128d commit 066ee29
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions jstests/core/geo_distinct.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
// Test distinct with geo queries SERVER-2135
// Tests distinct with geospatial field values.
// 1. Test distinct with geo values for 'key' (SERVER-2135)

t = db.commits
t.drop()
var coll = db.geo_distinct;
var res;

t.save( { _id : ObjectId( "4ce63ec2f360622431000013" ), loc : [ 55.59664, 13.00156 ], author : "FredrikL" } )
//
// 1. Test distinct with geo values for 'key'.
//

assert.commandWorked( db.runCommand( { distinct : 'commits', key : 'loc' } ) );
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() );

t.ensureIndex( { loc : '2d' } )
// Test distinct on GeoJSON points with/without a 2dsphere index.

printjson( t.getIndexes() )
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( db.runCommand( { distinct : 'commits', key : 'loc' } ) );
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 ] } ] );

// Test distinct on legacy points with/without a 2d index.

// (Note that distinct on a 2d-indexed field doesn't produce a list of coordinate pairs, since
// distinct logically operates on unique values in an array. Hence, the results are unintuitive and
// not semantically meaningful.)

coll.dropIndexes();

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' } ) );

res = coll.runCommand( 'distinct', { key: 'loc.coordinates' } );
assert.commandWorked( res );
assert.eq( res.values.sort(), [ 10, 20, 30 ] );

0 comments on commit 066ee29

Please sign in to comment.