Permalink
Browse files

Add test for using geo queries within a group command. SERVER-1742

  • Loading branch information...
1 parent 1d75a47 commit fd0a54bb7361d72f6db7e374c38da60333a55d18 @stbrody stbrody committed Sep 7, 2011
Showing with 35 additions and 0 deletions.
  1. +35 −0 jstests/geo_group.js
View
@@ -0,0 +1,35 @@
+t = db.geo_group;
+t.drop();
+
+n = 1;
+for ( var x=-100; x<100; x+=2 ){
+ for ( var y=-100; y<100; y+=2 ){
+ t.insert( { _id : n++ , loc : [ x , y ] } )
+ }
+}
+
+t.ensureIndex( { loc : "2d" } );
+
+// Test basic count with $near
+assert.eq(t.find().count(), 10000);
+assert.eq(t.find( { loc : { $within : {$center : [[56,8], 10]}}}).count(), 81);
+assert.eq(t.find( { loc : { $near : [56, 8, 10] } } ).count(), 81);
+
+// Test basic group that effectively does a count
+assert.eq(
+ t.group( {
+ reduce : function (obj, prev) { prev.sums = { count : prev.sums.count + 1} },
+ initial : { sums:{count:0} } }
+ ),
+ [ { "sums" : { "count" : 10000 } } ]
+);
+
+// Test basic group + $near that does a count
+assert.eq(
+ t.group( {
+ reduce : function (obj, prev) { prev.sums = { count : prev.sums.count + 1} },
+ initial : { sums:{count:0} },
+ cond : { loc : { $near : [56, 8, 10] } } }
+ ),
+ [ { "sums" : { "count" : 81 } } ]
+);

0 comments on commit fd0a54b

Please sign in to comment.