summaryrefslogtreecommitdiff
path: root/jstests/geo9.js
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-03-01 22:06:30 -0500
committerEliot Horowitz <eliot@10gen.com>2010-03-01 22:06:30 -0500
commit0a8e1f91c83bce14480e9cda00a1f630a5c64e93 (patch)
treebe66a1f462c66f235c7efca1ee23041fc1537731 /jstests/geo9.js
parent581980efa09ec2c6a516257c0a5ce4241e89e129 (diff)
downloadmongo-0a8e1f91c83bce14480e9cda00a1f630a5c64e93.tar.gz
handle multiple geo indexes with $near SERVER-686
Diffstat (limited to 'jstests/geo9.js')
-rw-r--r--jstests/geo9.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/geo9.js b/jstests/geo9.js
new file mode 100644
index 00000000000..8b6510f03b5
--- /dev/null
+++ b/jstests/geo9.js
@@ -0,0 +1,28 @@
+
+t = db.geo9
+t.drop();
+
+t.save( { _id : 1 , a : [ 10 , 10 ] , b : [ 50 , 50 ] } )
+t.save( { _id : 2 , a : [ 11 , 11 ] , b : [ 51 , 52 ] } )
+t.save( { _id : 3 , a : [ 12 , 12 ] , b : [ 52 , 52 ] } )
+
+t.save( { _id : 4 , a : [ 50 , 50 ] , b : [ 10 , 10 ] } )
+t.save( { _id : 5 , a : [ 51 , 51 ] , b : [ 11 , 11 ] } )
+t.save( { _id : 6 , a : [ 52 , 52 ] , b : [ 12 , 12 ] } )
+
+t.ensureIndex( { a : "2d" } )
+t.ensureIndex( { b : "2d" } )
+
+function check( field ){
+ var q = {}
+ q[field] = { $near : [ 11 , 11 ] }
+ arr = t.find( q ).limit(3).map(
+ function(z){
+ return Geo.distance( [ 11 , 11 ] , z[field] );
+ }
+ );
+ assert.eq( 2 * Math.sqrt( 2 ) , Array.sum( arr ) , "test " + field );
+}
+
+check( "a" )
+check( "b" )