summaryrefslogtreecommitdiff
path: root/jstests/sharding/query/explain_cmd.js
diff options
context:
space:
mode:
authorSanika Phanse <sanika.phanse@mongodb.com>2023-03-30 12:47:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-30 13:48:17 +0000
commitcf860fd6504eb80ea47905dab3b8b4c407a4b9f8 (patch)
tree542fca6b31754c5fe839ece796e66f5091186f34 /jstests/sharding/query/explain_cmd.js
parent222dde5f2593af7c0e4175696d2fdd6ca54e24cd (diff)
downloadmongo-cf860fd6504eb80ea47905dab3b8b4c407a4b9f8.tar.gz
SERVER-74952 Insert upsert document for single writes without shard keys
Diffstat (limited to 'jstests/sharding/query/explain_cmd.js')
-rw-r--r--jstests/sharding/query/explain_cmd.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/jstests/sharding/query/explain_cmd.js b/jstests/sharding/query/explain_cmd.js
index 00cce44d184..544c426f546 100644
--- a/jstests/sharding/query/explain_cmd.js
+++ b/jstests/sharding/query/explain_cmd.js
@@ -2,6 +2,8 @@
(function() {
'use strict';
+load("jstests/sharding/updateOne_without_shard_key/libs/write_without_shard_key_test_util.js");
+
// Create a cluster with 3 shards.
var st = new ShardingTest({shards: 2});
@@ -133,12 +135,25 @@ assert.eq(explain.queryPlanner.winningPlan.shards.length, 1);
// Check that the upsert didn't actually happen.
assert.eq(0, collSharded.count({a: 10}));
-// Explain an upsert operation which cannot be targeted, ensure an error is thrown
-explain = db.runCommand({
- explain: {update: collSharded.getName(), updates: [{q: {b: 10}, u: {b: 10}, upsert: true}]},
- verbosity: "allPlansExecution"
-});
-assert.commandFailed(explain, tojson(explain));
+if (WriteWithoutShardKeyTestUtil.isWriteWithoutShardKeyFeatureEnabled(collSharded.getDB())) {
+ // Explain an upsert operation which cannot be targeted and verify that it is successful.
+ // TODO SERVER-69922: Verify expected response.
+ explain = db.runCommand({
+ explain: {update: collSharded.getName(), updates: [{q: {b: 10}, u: {b: 10}, upsert: true}]},
+ verbosity: "allPlansExecution"
+ });
+ assert.commandWorked(explain, tojson(explain));
+ assert.eq(explain.queryPlanner.winningPlan.shards.length, 2);
+ // Check that the upsert didn't actually happen.
+ assert.eq(0, collSharded.count({b: 10}));
+} else {
+ // Explain an upsert operation which cannot be targeted, ensure an error is thrown
+ explain = db.runCommand({
+ explain: {update: collSharded.getName(), updates: [{q: {b: 10}, u: {b: 10}, upsert: true}]},
+ verbosity: "allPlansExecution"
+ });
+ assert.commandFailed(explain, tojson(explain));
+}
// Explain a changeStream, ensure an error is thrown under snapshot read concern.
const session = db.getMongo().startSession();