Files
mongo/jstests/aggregation/explain/non_existent_database.js
karlbozdogan 127300dde1 SERVER-108882 Explain operations should not implicitly create a database on a sharded cluster (#48752)
GitOrigin-RevId: 0ed41d286b41d866fc80ddc27d67f30b54c0d155
2026-03-03 00:24:28 +00:00

33 lines
1.4 KiB
JavaScript

/**
* Tests the behavior of explain() when used on a database that does not exist.
* We should get back an EOF plan
* @tags: [
* # Implicit sharding creates the collection, directly contradicting this test
* assumes_no_implicit_collection_creation_on_get_collection,
* # Wrapping in $facet changes the explain output
* do_not_wrap_aggregations_in_facets,
* # Older versions have different explain behaviour around non-existent DBs
* requires_fcv_83,
* ]
*/
import {isMongos} from "jstests/concurrency/fsm_workload_helpers/server_types.js";
import {checkSbeFullyEnabled} from "jstests/libs/query/sbe_util.js";
const isSbeFullyEnabled = checkSbeFullyEnabled(db);
const testDB = db.getSiblingDB(jsTestName());
assert.commandWorked(testDB.dropDatabase({}));
// Do it twice to make sure the DB does not get created as a side-effect.
for (let i = 0; i < 2; i++) {
const result = testDB.test.explain().aggregate([]);
if (!isSbeFullyEnabled || isMongos(testDB)) {
assert.eq(result.queryPlanner.winningPlan.stage, "EOF", result);
assert.eq(result.queryPlanner.winningPlan.type, "nonExistentNamespace", result);
} else {
// SBE has a different explain format
assert.eq(result.queryPlanner.winningPlan.queryPlan.stage, "EOF", result);
assert.eq(result.queryPlanner.winningPlan.queryPlan.type, "nonExistentNamespace", result);
}
}