summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-05-20 19:14:54 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2019-05-22 16:38:40 -0400
commit7ac68bb3418650654599b6ffb768daf4bacc979d (patch)
treed5c225e46bc468f59950219ffb7df840fa98e945 /src/mongo/shell
parent5594eeb9c42f5a28ebb20c8fcce87a2a1a01f6a5 (diff)
downloadmongo-7ac68bb3418650654599b6ffb768daf4bacc979d.tar.gz
SERVER-41249 Fix special cases for $out to include $merge
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/db.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 2d9f0789db9..87559699b7d 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -232,13 +232,18 @@ var DB;
const pipeline = cmdObj.pipeline;
- // Check whether the pipeline has an $out stage. If not, we may run on a Secondary and
- // should attach a readPreference.
- const hasOutStage =
- pipeline.length >= 1 && pipeline[pipeline.length - 1].hasOwnProperty("$out");
+ // Check whether the pipeline has a stage which performs writes like $out. If not, we may
+ // run on a Secondary and should attach a readPreference.
+ const hasWritingStage = (function() {
+ if (pipeline.length == 0) {
+ return false;
+ }
+ const lastStage = pipeline[pipeline.length - 1];
+ return lastStage.hasOwnProperty("$out") || lastStage.hasOwnProperty("$merge");
+ }());
const doAgg = function(cmdObj) {
- return hasOutStage ? this.runCommand(cmdObj) : this.runReadCommand(cmdObj);
+ return hasWritingStage ? this.runCommand(cmdObj) : this.runReadCommand(cmdObj);
}.bind(this);
const res = doAgg(cmdObj);