2011-07-06 19:37:23 +02:00
|
|
|
// Test sanity of geo queries with a lot of points
|
|
|
|
|
2017-06-07 16:03:57 +02:00
|
|
|
(function() {
|
2019-07-27 00:20:35 +02:00
|
|
|
"use strict";
|
|
|
|
const conn = MongoRunner.runMongod();
|
|
|
|
assert.neq(null, conn, "mongod failed to start.");
|
|
|
|
const db = conn.getDB("test");
|
2012-04-09 05:39:11 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var maxFields = 3;
|
2011-07-06 19:37:23 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
for (var fields = 1; fields < maxFields; fields++) {
|
|
|
|
var coll = db.testMnyPts;
|
|
|
|
coll.drop();
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var totalPts = 500 * 1000;
|
2014-05-14 20:11:11 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var bulk = coll.initializeUnorderedBulkOp();
|
|
|
|
// Add points in a 100x100 grid
|
|
|
|
for (var i = 0; i < totalPts; i++) {
|
|
|
|
var ii = i % 10000;
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var doc = {loc: [ii % 100, Math.floor(ii / 100)]};
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Add fields with different kinds of data
|
2016-03-09 18:17:50 +01:00
|
|
|
for (var j = 0; j < fields; j++) {
|
2016-02-04 18:29:53 +01:00
|
|
|
var field = null;
|
2016-03-09 18:17:50 +01:00
|
|
|
|
|
|
|
if (j % 3 == 0) {
|
2019-07-27 00:20:35 +02:00
|
|
|
// Make half the points not searchable
|
|
|
|
field = "abcdefg" + (i % 2 == 0 ? "h" : "");
|
2016-03-09 18:17:50 +01:00
|
|
|
} else if (j % 3 == 1) {
|
2019-07-27 00:20:35 +02:00
|
|
|
field = new Date();
|
2016-03-09 18:17:50 +01:00
|
|
|
} else {
|
2016-02-04 18:29:53 +01:00
|
|
|
field = true;
|
2011-07-06 19:37:23 +02:00
|
|
|
}
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
doc["field" + j] = field;
|
2011-07-06 19:37:23 +02:00
|
|
|
}
|
2014-05-14 20:11:11 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
bulk.insert(doc);
|
|
|
|
}
|
|
|
|
assert.writeOK(bulk.execute());
|
|
|
|
|
|
|
|
// Create the query for the additional fields
|
|
|
|
const queryFields = {};
|
|
|
|
for (var j = 0; j < fields; j++) {
|
|
|
|
var field = null;
|
|
|
|
|
|
|
|
if (j % 3 == 0) {
|
|
|
|
field = "abcdefg";
|
|
|
|
} else if (j % 3 == 1) {
|
|
|
|
field = {$lte: new Date()};
|
|
|
|
} else {
|
|
|
|
field = true;
|
2011-07-06 19:37:23 +02:00
|
|
|
}
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
queryFields["field" + j] = field;
|
|
|
|
}
|
|
|
|
|
|
|
|
coll.ensureIndex({loc: "2d"});
|
|
|
|
|
|
|
|
// Check that quarter of points in each quadrant
|
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
var x = i % 2;
|
|
|
|
var y = Math.floor(i / 2);
|
|
|
|
|
|
|
|
var box = [[0, 0], [49, 49]];
|
|
|
|
box[0][0] += (x == 1 ? 50 : 0);
|
|
|
|
box[1][0] += (x == 1 ? 50 : 0);
|
|
|
|
box[0][1] += (y == 1 ? 50 : 0);
|
|
|
|
box[1][1] += (y == 1 ? 50 : 0);
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Now only half of each result comes back
|
|
|
|
assert.eq(totalPts / (4 * 2),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$box: box}}}, queryFields)).count());
|
|
|
|
assert.eq(totalPts / (4 * 2),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$box: box}}}, queryFields)).itcount());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that half of points in each half
|
|
|
|
for (var i = 0; i < 2; i++) {
|
|
|
|
var box = [[0, 0], [49, 99]];
|
|
|
|
box[0][0] += (i == 1 ? 50 : 0);
|
|
|
|
box[1][0] += (i == 1 ? 50 : 0);
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
assert.eq(totalPts / (2 * 2),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$box: box}}}, queryFields)).count());
|
|
|
|
assert.eq(totalPts / (2 * 2),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$box: box}}}, queryFields)).itcount());
|
2011-07-06 19:37:23 +02:00
|
|
|
}
|
2016-03-09 18:17:50 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Check that all but corner set of points in radius
|
|
|
|
var circle = [[0, 0], (100 - 1) * Math.sqrt(2) - 0.25];
|
|
|
|
|
|
|
|
// All [99,x] pts are field0 : "abcdefg"
|
|
|
|
assert.eq(totalPts / 2 - totalPts / (100 * 100),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$center: circle}}}, queryFields)).count());
|
|
|
|
assert.eq(totalPts / 2 - totalPts / (100 * 100),
|
|
|
|
coll.find(Object.extend({loc: {$within: {$center: circle}}}, queryFields)).itcount());
|
|
|
|
}
|
|
|
|
|
|
|
|
MongoRunner.stopMongod(conn);
|
2017-06-07 16:03:57 +02:00
|
|
|
})();
|