Files
mongo/jstests/core/geo_array1.js

39 lines
858 B
JavaScript
Raw Normal View History

// Make sure many locations in one doc works, in the form of an array
t = db.geoarray1;
2013-01-18 11:26:30 -05:00
function test(index) {
t.drop();
var locObj = [];
// 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
}
}
2013-01-18 11:26:30 -05:00
// Add docs with all these locations
for (var i = 0; i < 300; i++) {
t.insert({loc: locObj});
2013-01-18 11:26:30 -05:00
}
2013-01-18 11:26:30 -05:00
if (index) {
t.ensureIndex({loc: "2d"});
2013-01-18 11:26:30 -05:00
}
2013-01-18 11:26:30 -05:00
// Pull them back
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
}
}
}
2013-01-18 11:26:30 -05:00
test(true);
test(false);