summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2018-06-18 23:34:49 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2018-06-18 23:34:49 -0400
commit7bc7864fc042b69d36a88c6839c5dd5b4eb20693 (patch)
treee103e752e5d708aa22dca3ae99ef269d79a5d917 /jstests/noPassthrough
parent7c89f48c4f1f1e3ede2931ab602fa118281530a2 (diff)
downloadmongo-7bc7864fc042b69d36a88c6839c5dd5b4eb20693.tar.gz
SERVER-35043, SERVER-22949: move geoNear implementation into aggregation
This commit removes the geoNear command and moves its implementation into the aggregation framework. Users should use the aggregate command with a $geoNear stage. The implementation rewrite additionally removes the limit in the $geoNear aggregation stage. To limit the number of results, use a $limit stage.
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r--jstests/noPassthrough/commands_handle_kill.js19
-rw-r--r--jstests/noPassthrough/commands_preserve_exec_error_code.js3
-rw-r--r--jstests/noPassthrough/currentop_query.js35
-rw-r--r--jstests/noPassthrough/geo_full.js82
-rw-r--r--jstests/noPassthrough/global_operation_latency_histogram.js14
-rw-r--r--jstests/noPassthrough/log_format_slowms_samplerate_loglevel.js19
-rw-r--r--jstests/noPassthrough/readConcern_snapshot.js13
-rw-r--r--jstests/noPassthrough/readConcern_snapshot_mongos.js9
-rw-r--r--jstests/noPassthrough/read_concern_snapshot_yielding.js16
-rw-r--r--jstests/noPassthrough/read_majority_reads.js28
-rw-r--r--jstests/noPassthrough/shell_can_use_read_concern.js16
11 files changed, 88 insertions, 166 deletions
diff --git a/jstests/noPassthrough/commands_handle_kill.js b/jstests/noPassthrough/commands_handle_kill.js
index f03e40036a1..59470f63620 100644
--- a/jstests/noPassthrough/commands_handle_kill.js
+++ b/jstests/noPassthrough/commands_handle_kill.js
@@ -179,10 +179,21 @@ if (${ canYield }) {
{findAndModify: collName, filter: {fakeField: {$gt: 0}}, update: {$inc: {a: 1}}});
assertCommandPropogatesPlanExecutorKillReason(
- {geoNear: collName, near: {type: "Point", coordinates: [0, 0]}, spherical: true}, {
- customSetup: function() {
- assert.commandWorked(coll.createIndex({geoField: "2dsphere"}));
- }
+ {
+ aggregate: collName,
+ cursor: {},
+ pipeline: [{
+ $geoNear: {
+ near: {type: "Point", coordinates: [0, 0]},
+ spherical: true,
+ distanceField: "dis"
+ }
+ }]
+ },
+ {
+ customSetup: function() {
+ assert.commandWorked(coll.createIndex({geoField: "2dsphere"}));
+ }
});
assertCommandPropogatesPlanExecutorKillReason({find: coll.getName(), filter: {}});
diff --git a/jstests/noPassthrough/commands_preserve_exec_error_code.js b/jstests/noPassthrough/commands_preserve_exec_error_code.js
index 38e12da2740..373461ad4f0 100644
--- a/jstests/noPassthrough/commands_preserve_exec_error_code.js
+++ b/jstests/noPassthrough/commands_preserve_exec_error_code.js
@@ -37,8 +37,9 @@
assertFailsWithInternalError(() => coll.deleteOne({_id: 1}));
assertFailsWithInternalError(() => coll.count({_id: 1}));
assertFailsWithInternalError(() => coll.aggregate([]).itcount());
+ assertFailsWithInternalError(
+ () => coll.aggregate([{$geoNear: {near: [0, 0], distanceField: "d"}}]).itcount());
assertCmdFailsWithInternalError({distinct: coll.getName(), key: "_id"});
- assertCmdFailsWithInternalError({geoNear: coll.getName(), near: [0, 0]});
assertCmdFailsWithInternalError(
{findAndModify: coll.getName(), query: {_id: 1}, update: {$set: {x: 2}}});
diff --git a/jstests/noPassthrough/currentop_query.js b/jstests/noPassthrough/currentop_query.js
index 1eb1655f035..dfa7ae80fee 100644
--- a/jstests/noPassthrough/currentop_query.js
+++ b/jstests/noPassthrough/currentop_query.js
@@ -337,30 +337,39 @@
}
//
- // Confirm currentOp content for geoNear.
+ // Confirm currentOp content for the $geoNear aggregation stage.
//
dropAndRecreateTestCollection();
for (let i = 0; i < 10; ++i) {
- assert.writeOK(coll.insert({a: i, loc: {type: "Point", coordinates: [i, i]}}));
+ assert.commandWorked(
+ coll.insert({a: i, loc: {type: "Point", coordinates: [i, i]}}));
}
assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
-
confirmCurrentOpContents({
test: function(db) {
assert.commandWorked(db.runCommand({
- geoNear: "currentop_query",
- near: {type: "Point", coordinates: [1, 1]},
- spherical: true,
- query: {$comment: "currentop_query"},
- collation: {locale: "fr"}
+ aggregate: "currentop_query",
+ cursor: {},
+ pipeline: [{
+ $geoNear: {
+ near: {type: "Point", coordinates: [1, 1]},
+ distanceField: "dist",
+ spherical: true,
+ query: {$comment: "currentop_query"},
+ }
+ }],
+ collation: {locale: "fr"},
+ comment: "currentop_query",
}));
},
- command: "geoNear",
planSummary: "GEO_NEAR_2DSPHERE { loc: \"2dsphere\" }",
- currentOpFilter: {
- "command.query.$comment": "currentop_query",
- "command.collation": {locale: "fr"}
- }
+ currentOpFilter: commandOrOriginatingCommand({
+ "aggregate": {$exists: true},
+ "pipeline.0.$geoNear.query.$comment": "currentop_query",
+ "collation": {locale: "fr"},
+ "comment": "currentop_query",
+ },
+ isRemoteShardCurOp)
});
//
diff --git a/jstests/noPassthrough/geo_full.js b/jstests/noPassthrough/geo_full.js
index 6486679ea4e..b4622f46527 100644
--- a/jstests/noPassthrough/geo_full.js
+++ b/jstests/noPassthrough/geo_full.js
@@ -500,8 +500,6 @@
"poly.docIn": randYesQuery()
}).count());
- var defaultDocLimit = 100;
-
// $near
print("Near query...");
assert.eq(
@@ -523,60 +521,38 @@
results.sphere.locsIn);
}
- // geoNear
- // results limited by size of objects
- if (data.maxLocs < defaultDocLimit) {
- // GeoNear query
- print("GeoNear query...");
- // GeoNear command has a default doc limit 100.
- assert.eq(
- Math.min(defaultDocLimit, results.center.docsIn),
- t.getDB()
- .runCommand(
- {geoNear: "testAllGeo", near: query.center, maxDistance: query.radius})
- .results.length,
- "GeoNear query: center: " + query.center + "; radius: " + query.radius +
- "; docs: " + results.center.docsIn + "; locs: " + results.center.locsIn);
-
- var num = Math.min(2 * defaultDocLimit, 2 * results.center.docsIn);
-
- var output = db.runCommand({
- geoNear: "testAllGeo",
- near: query.center,
- maxDistance: query.radius,
- includeLocs: true,
- num: num
- }).results;
-
- assert.eq(Math.min(num, results.center.docsIn),
- output.length,
- "GeoNear query with limit of " + num + ": center: " + query.center +
- "; radius: " + query.radius + "; docs: " + results.center.docsIn +
- "; locs: " + results.center.locsIn);
-
- var distance = 0;
+ // $geoNear aggregation stage.
+ const aggregationLimit = 2 * results.center.docsIn;
+ if (aggregationLimit > 0) {
+ var output = t.aggregate([
+ {
+ $geoNear: {
+ near: query.center,
+ maxDistance: query.radius,
+ includeLocs: "pt",
+ distanceField: "dis",
+ }
+ },
+ {$limit: aggregationLimit}
+ ]).toArray();
+
+ const errmsg = {
+ limit: aggregationLimit,
+ center: query.center,
+ radius: query.radius,
+ docs: results.center.docsIn,
+ locs: results.center.locsIn,
+ actualResult: output
+ };
+ assert.eq(results.center.docsIn, output.length, tojson(errmsg));
+
+ let lastDistance = 0;
for (var i = 0; i < output.length; i++) {
var retDistance = output[i].dis;
- var retLoc = locArray(output[i].loc);
-
- var arrLocs = locsArray(output[i].obj.locs);
-
- assert.contains(retLoc, arrLocs);
-
- var distInObj = false;
- for (var j = 0; j < arrLocs.length && distInObj == false; j++) {
- var newDistance = Geo.distance(locArray(query.center), arrLocs[j]);
- distInObj = (newDistance >= retDistance - 0.0001 &&
- newDistance <= retDistance + 0.0001);
- }
-
- assert(distInObj);
- assert.between(retDistance - 0.0001,
- Geo.distance(locArray(query.center), retLoc),
- retDistance + 0.0001);
+ assert.close(retDistance, Geo.distance(locArray(query.center), output[i].pt));
assert.lte(retDistance, query.radius);
- assert.gte(retDistance, distance);
- distance = retDistance;
+ assert.gte(retDistance, lastDistance);
+ lastDistance = retDistance;
}
}
diff --git a/jstests/noPassthrough/global_operation_latency_histogram.js b/jstests/noPassthrough/global_operation_latency_histogram.js
index 3e5b4bcd8c8..d6ed2cc3c6e 100644
--- a/jstests/noPassthrough/global_operation_latency_histogram.js
+++ b/jstests/noPassthrough/global_operation_latency_histogram.js
@@ -102,11 +102,17 @@
assert.commandWorked(testColl.createIndex({pt: "2dsphere"}));
lastHistogram = checkHistogramDiff(0, 0, 1);
- // GeoNear
+ // $geoNear aggregation stage
assert.commandWorked(testDB.runCommand({
- geoNear: testColl.getName(),
- near: {type: "Point", coordinates: [0, 0]},
- spherical: true
+ aggregate: testColl.getName(),
+ pipeline: [{
+ $geoNear: {
+ near: {type: "Point", coordinates: [0, 0]},
+ spherical: true,
+ distanceField: "dist",
+ }
+ }],
+ cursor: {},
}));
lastHistogram = checkHistogramDiff(1, 0, 0);
diff --git a/jstests/noPassthrough/log_format_slowms_samplerate_loglevel.js b/jstests/noPassthrough/log_format_slowms_samplerate_loglevel.js
index 82893ddd1a2..3d0aa0dfbf3 100644
--- a/jstests/noPassthrough/log_format_slowms_samplerate_loglevel.js
+++ b/jstests/noPassthrough/log_format_slowms_samplerate_loglevel.js
@@ -320,25 +320,6 @@
keysDeleted: 1
})
},
- {
- test: function(db) {
- assert.commandWorked(db.runCommand({
- geoNear: coll.getName(),
- near: {type: "Point", coordinates: [1, 1]},
- spherical: true,
- query: {$comment: logFormatTestComment},
- collation: {locale: "fr"}
- }));
- },
- logFields: {
- command: "geoNear",
- geoNear: coll.getName(),
- near: {type: "Point", coordinates: [1, 1]},
- planSummary: "GEO_NEAR_2DSPHERE { loc: \"2dsphere\" }",
- query: {$comment: logFormatTestComment},
- collation: {locale: "fr"}
- }
- }
];
// Confirm log contains collation for find command.
diff --git a/jstests/noPassthrough/readConcern_snapshot.js b/jstests/noPassthrough/readConcern_snapshot.js
index 7927593c911..8878e596987 100644
--- a/jstests/noPassthrough/readConcern_snapshot.js
+++ b/jstests/noPassthrough/readConcern_snapshot.js
@@ -158,18 +158,5 @@
assert.commandWorked(session.abortTransaction_forTesting());
session.endSession();
- // TODO: SERVER-34113 Remove this test when we completely remove snapshot
- // reads since this command is not supported with transaction api.
- // readConcern 'snapshot' is supported by geoNear.
- session = rst.getPrimary().getDB(dbName).getMongo().startSession({causalConsistency: false});
- sessionDb = session.getDatabase(dbName);
- assert.commandWorked(sessionDb.runCommand({
- geoNear: collName,
- near: [0, 0],
- readConcern: {level: "snapshot"},
- txnNumber: NumberLong(0),
- }));
-
- session.endSession();
rst.stopSet();
}());
diff --git a/jstests/noPassthrough/readConcern_snapshot_mongos.js b/jstests/noPassthrough/readConcern_snapshot_mongos.js
index 2d780eec4d5..61e7404a4ca 100644
--- a/jstests/noPassthrough/readConcern_snapshot_mongos.js
+++ b/jstests/noPassthrough/readConcern_snapshot_mongos.js
@@ -143,14 +143,5 @@
}),
ErrorCodes.InvalidOptions);
- // TODO SERVER-33712: Add snapshot support for geoNear on mongos.
- assert.commandFailedWithCode(sessionDb.runCommand({
- geoNear: collName,
- near: [0, 0],
- readConcern: {level: "snapshot"},
- txnNumber: NumberLong(txnNumber++)
- }),
- ErrorCodes.InvalidOptions);
-
st.stop();
}());
diff --git a/jstests/noPassthrough/read_concern_snapshot_yielding.js b/jstests/noPassthrough/read_concern_snapshot_yielding.js
index a88ddb5fe05..2a44a57d750 100644
--- a/jstests/noPassthrough/read_concern_snapshot_yielding.js
+++ b/jstests/noPassthrough/read_concern_snapshot_yielding.js
@@ -242,22 +242,6 @@
assert.eq(res.cursor.firstBatch.length, TestData.numDocs, tojson(res));
}, {"command.pipeline": [{$match: {x: 1}}]});
- // TODO: SERVER-34113 Remove this test when we completely remove snapshot
- // reads since this command is not supported with transaction api.
- // Test geoNear.
- testCommand(function() {
- const sessionId = db.getMongo().startSession({causalConsistency: false}).getSessionId();
- const res = assert.commandWorked(db.runCommand({
- geoNear: "coll",
- near: [0, 0],
- readConcern: {level: "snapshot"},
- lsid: sessionId,
- txnNumber: NumberLong(0)
- }));
- assert(res.hasOwnProperty("results"));
- assert.eq(res.results.length, TestData.numDocs, tojson(res));
- }, {"command.geoNear": "coll"});
-
// Test getMore with an initial find batchSize of 0. Interrupt behavior of a getMore is not
// expected to change with a change of batchSize in the originating command.
testCommand(function() {
diff --git a/jstests/noPassthrough/read_majority_reads.js b/jstests/noPassthrough/read_majority_reads.js
index eec0ddc80cb..c10a86eac41 100644
--- a/jstests/noPassthrough/read_majority_reads.js
+++ b/jstests/noPassthrough/read_majority_reads.js
@@ -7,7 +7,6 @@
* - distinct
* - count
* - parallelCollectionScan
- * - geoNear
* - geoSearch
*
* Each operation is tested on a single node, and (if supported) through mongos on both sharded and
@@ -55,6 +54,13 @@
'aggregate',
{readConcern: {level: 'majority'}, cursor: {batchSize: 0}, pipeline: []})));
},
+ aggregateGeoNear: function(coll) {
+ return makeCursor(coll.getDB(), assert.commandWorked(coll.runCommand('aggregate', {
+ readConcern: {level: 'majority'},
+ cursor: {batchSize: 0},
+ pipeline: [{$geoNear: {near: [0, 0], distanceField: "d", spherical: true}}]
+ })));
+ },
parallelCollectionScan: function(coll) {
var res = coll.runCommand('parallelCollectionScan',
{readConcern: {level: 'majority'}, numCursors: 1});
@@ -101,20 +107,6 @@
expectedBefore: 'before',
expectedAfter: 'after',
},
- geoNear: {
- run: function(coll) {
- var res = coll.runCommand('geoNear', {
- readConcern: {level: 'majority'},
- near: [0, 0],
- spherical: true,
- });
- assert.commandWorked(res);
- assert.eq(res.results.length, 1, tojson(res));
- return res.results[0].obj.state;
- },
- expectedBefore: 'before',
- expectedAfter: 'after',
- },
geoSearch: {
run: function(coll) {
var res = coll.runCommand('geoSearch', {
@@ -140,20 +132,21 @@
assert.commandWorked(mongodConnection.adminCommand({"setCommittedSnapshot": snapshot}));
}
+ assert.commandWorked(coll.createIndex({point: '2dsphere'}));
for (var testName in cursorTestCases) {
jsTestLog('Running ' + testName + ' against ' + coll.toString());
var getCursor = cursorTestCases[testName];
// Setup initial state.
assert.writeOK(coll.remove({}));
- assert.writeOK(coll.save({_id: 1, state: 'before'}));
+ assert.writeOK(coll.save({_id: 1, state: 'before', point: [0, 0]}));
setCommittedSnapshot(makeSnapshot());
// Check initial conditions.
assert.eq(getCursor(coll).next().state, 'before');
// Change state without making it committed.
- assert.writeOK(coll.save({_id: 1, state: 'after'}));
+ assert.writeOK(coll.save({_id: 1, state: 'after', point: [0, 0]}));
// Cursor still sees old state.
assert.eq(getCursor(coll).next().state, 'before');
@@ -171,7 +164,6 @@
assert.eq(oldCursor.next().state, 'after');
}
- assert.commandWorked(coll.ensureIndex({point: '2dsphere'}));
assert.commandWorked(coll.ensureIndex({point: 'geoHaystack', _id: 1}, {bucketSize: 1}));
for (var testName in nonCursorTestCases) {
jsTestLog('Running ' + testName + ' against ' + coll.toString());
diff --git a/jstests/noPassthrough/shell_can_use_read_concern.js b/jstests/noPassthrough/shell_can_use_read_concern.js
index 5a3134af9cb..dd9f7ed6ec1 100644
--- a/jstests/noPassthrough/shell_can_use_read_concern.js
+++ b/jstests/noPassthrough/shell_can_use_read_concern.js
@@ -226,22 +226,6 @@
});
//
- // Tests for the "geoNear" command.
- //
-
- testCommandCanBeCausallyConsistent(function() {
- assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
- }, {expectedSession: withSession, expectedAfterClusterTime: false});
-
- testCommandCanBeCausallyConsistent(function() {
- assert.commandWorked(db.runCommand({
- geoNear: coll.getName(),
- near: {type: "Point", coordinates: [0, 0]},
- spherical: true
- }));
- });
-
- //
// Tests for the "geoSearch" command.
//