summaryrefslogtreecommitdiff
path: root/jstests/core/geo_group.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/geo_group.js')
-rw-r--r--jstests/core/geo_group.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/jstests/core/geo_group.js b/jstests/core/geo_group.js
new file mode 100644
index 00000000000..32e06890568
--- /dev/null
+++ b/jstests/core/geo_group.js
@@ -0,0 +1,37 @@
+t = db.geo_group;
+t.drop();
+
+n = 1;
+var bulk = t.initializeUnorderedBulkOp();
+for ( var x=-100; x<100; x+=2 ){
+ for ( var y=-100; y<100; y+=2 ){
+ bulk.insert( { _id : n++ , loc : [ x , y ] } );
+ }
+}
+assert.writeOK(bulk.execute());
+
+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 } } ]
+);