2011-03-25 20:38:07 -04:00
|
|
|
// Make sure many locations in one doc works, in the form of an array
|
|
|
|
|
|
2016-02-04 12:29:01 -05:00
|
|
|
t = db.geoarray1;
|
2013-01-18 11:26:30 -05:00
|
|
|
function test(index) {
|
|
|
|
|
t.drop();
|
2011-03-25 20:38:07 -04:00
|
|
|
|
2016-02-04 12:29:01 -05:00
|
|
|
var locObj = [];
|
2016-03-09 12:17:50 -05:00
|
|
|
// Add locations everywhere
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
for (var j = 0; j < 10; j++) {
|
|
|
|
|
if (j % 2 == 0)
|
|
|
|
|
locObj.push([i, j]);
|
|
|
|
|
else
|
|
|
|
|
locObj.push({x: i, y: j});
|
2013-01-18 11:26:30 -05:00
|
|
|
}
|
2016-03-09 12:17:50 -05:00
|
|
|
}
|
2011-03-25 20:38:07 -04:00
|
|
|
|
2013-01-18 11:26:30 -05:00
|
|
|
// Add docs with all these locations
|
2016-03-09 12:17:50 -05:00
|
|
|
for (var i = 0; i < 300; i++) {
|
|
|
|
|
t.insert({loc: locObj});
|
2013-01-18 11:26:30 -05:00
|
|
|
}
|
2011-03-25 20:38:07 -04:00
|
|
|
|
2013-01-18 11:26:30 -05:00
|
|
|
if (index) {
|
2016-03-09 12:17:50 -05:00
|
|
|
t.ensureIndex({loc: "2d"});
|
2013-01-18 11:26:30 -05:00
|
|
|
}
|
2011-03-25 20:38:07 -04:00
|
|
|
|
2013-01-18 11:26:30 -05:00
|
|
|
// Pull them back
|
2016-03-09 12:17:50 -05:00
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
for (var j = 0; j < 10; j++) {
|
|
|
|
|
assert.eq(
|
|
|
|
|
300,
|
|
|
|
|
t.find({loc: {$within: {$box: [[i - 0.5, j - 0.5], [i + 0.5, j + 0.5]]}}}).count());
|
2013-01-18 11:26:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-25 20:38:07 -04:00
|
|
|
}
|
2013-01-18 11:26:30 -05:00
|
|
|
|
2016-02-04 12:29:01 -05:00
|
|
|
test(true);
|
|
|
|
|
test(false);
|