diff options
author | Benety Goh <benety@mongodb.com> | 2021-11-10 21:06:48 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-11 02:32:37 +0000 |
commit | b4a2ef74d21804dda8540fc7f4bf8edab12e0c98 (patch) | |
tree | 939d24b9d82ccbbe533b7d99941a45dafe4524ff /jstests | |
parent | 5c19a427713891054cafa9b7a002d65dd5668189 (diff) | |
download | mongo-b4a2ef74d21804dda8540fc7f4bf8edab12e0c98.tar.gz |
SERVER-61246 clean up geo_polygon3.js
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/geo_polygon3.js | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/jstests/core/geo_polygon3.js b/jstests/core/geo_polygon3.js index d871f85663d..c8167bc685b 100644 --- a/jstests/core/geo_polygon3.js +++ b/jstests/core/geo_polygon3.js @@ -7,41 +7,46 @@ const collNamePrefix = 'geo_polygon3_'; -const numTests = 31; +// See https://docs.mongodb.com/manual/tutorial/build-a-2d-index/ +const bits = [2, 3, 4, 5, 6, 8, 11, 13, 15, 18, 27, 32]; -for (let n = 0; n < numTests; n++) { - let t = db.getCollection(collNamePrefix + 'triangle_and_square_' + n); +bits.forEach((precision) => { + let t = db.getCollection(collNamePrefix + 'triangle_and_square_' + precision + '_bits'); t.drop(); - let num = 0; + assert.commandWorked(t.createIndex({loc: "2d"}, {bits: precision})); + + let docs = []; + let docId = 0; for (let x = 1; x < 9; x++) { for (let y = 1; y < 9; y++) { - let o = {_id: num++, loc: [x, y]}; - assert.commandWorked(t.insert(o)); + docs.push({_id: docId++, loc: [x, y]}); } } - - assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 2 + n})); + assert.commandWorked(t.insert(docs)); const triangle = [[0, 0], [1, 1], [0, 2]]; // Look at only a small slice of the data within a triangle - assert.eq(1, t.find({loc: {"$within": {"$polygon": triangle}}}).itcount(), "Triangle Test"); + assert.eq(1, t.countDocuments({loc: {"$within": {"$polygon": triangle}}}), "Triangle Test"); let boxBounds = [[0, 0], [0, 10], [10, 10], [10, 0]]; - assert.eq( - num, t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(), "Bounding Box Test"); + assert.eq(docs.length, + t.countDocuments({loc: {"$within": {"$polygon": boxBounds}}}), + "Bounding Box Test"); // Look in a box much bigger than the one we have data in boxBounds = [[-100, -100], [-100, 100], [100, 100], [100, -100]]; - assert.eq(num, - t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(), + assert.eq(docs.length, + t.countDocuments({loc: {"$within": {"$polygon": boxBounds}}}), "Big Bounding Box Test"); - t = db.getCollection(collNamePrefix + 'pacman_' + n); + t = db.getCollection(collNamePrefix + 'pacman_' + precision + '_bits'); t.drop(); + assert.commandWorked(t.createIndex({loc: "2d"}, {bits: precision})); + const pacman = [ [0, 2], [0, 4], @@ -54,16 +59,16 @@ for (let n = 0; n < numTests; n++) { [2, 0] // Bottom ]; - assert.commandWorked(t.insert({loc: [1, 3]})); // Add a point that's in - assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 2 + n})); + assert.commandWorked(t.insert({_id: docId++, loc: [1, 3]})); // Add a point that's in - assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman single point"); + assert.eq(1, t.countDocuments({loc: {$within: {$polygon: pacman}}}), "Pacman single point"); - assert.commandWorked( - t.insert({loc: [5, 3]})); // Add a point that's out right in the mouth opening - assert.commandWorked(t.insert({loc: [3, 7]})); // Add a point above the center of the head - assert.commandWorked(t.insert({loc: [3, -1]})); // Add a point below the center of the bottom + docs = []; + docs.push({_id: docId++, loc: [5, 3]}); // Add a point that's out right in the mouth opening + docs.push({_id: docId++, loc: [3, 7]}); // Add a point below the center of the bottom + docs.push({_id: docId++, loc: [3, -1]}); // Add a point above the center of the head + assert.commandWorked(t.insert(docs)); - assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman double point"); -} + assert.eq(1, t.countDocuments({loc: {$within: {$polygon: pacman}}}), "Pacman double point"); +}); })(); |