|
repro
const rst = new ReplSetTest({nodes: 1});
|
rst.startSet();
|
rst.initiate();
|
rst.awaitSecondaryNodes();const dbName = "nonexistant_db";let db = rst.getPrimary().getDB(dbName);
|
db.dropDatabase();
|
//let resRS = db.runCommand({explain: { aggregate: "test", cursor: {}, pipeline: [{$match: {a: 1}}, {$sort: {b: 1}}, {$group: {_id: "$c"}}]}});
|
let resRS = db.runCommand({ aggregate: "test", cursor: {}, pipeline: [{$collStats: {}}]});const st = new ShardingTest({shards: 2, mongo: 1, config: 1});
|
db = st.s0.getDB(dbName);
|
db.dropDatabase();
|
//let resSH = db.runCommand({explain: { aggregate: "test", cursor: {}, pipeline: [{$match: {a: 1}}, {$sort: {b: 1}}, {$group: {_id: "$c"}}]}});
|
let resSH = db.runCommand({ aggregate: "test", cursor: {}, pipeline: [{$collStats: {}}]});
|
print("foo");
|
printjson(resRS);
|
printjson(resSH);
|
output
{
|
"cursor" : {
|
"firstBatch" : [
|
{
|
"ns" : "nonexistant_db.test",
|
"host" : "REDACTED:20000",
|
"localTime" : ISODate("2023-12-06T20:06:34.872Z")
|
}
|
],
|
"id" : NumberLong(0),
|
"ns" : "nonexistant_db.test"
|
},
|
"ok" : 1,
|
"$clusterTime" : {
|
"clusterTime" : Timestamp(1701893194, 18),
|
"signature" : {
|
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
|
"keyId" : NumberLong(0)
|
}
|
},
|
"operationTime" : Timestamp(1701893194, 18)
|
}
|
{
|
"ok" : 0,
|
"errmsg" : "Unable to retrieve information for $collStats stage :: caused by :: database nonexistant_db not found",
|
"code" : 26,
|
"codeName" : "NamespaceNotFound",
|
"$clusterTime" : {
|
"clusterTime" : Timestamp(1701893198, 13),
|
"signature" : {
|
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
|
"keyId" : NumberLong(0)
|
}
|
},
|
"operationTime" : Timestamp(1701893198, 13)
|
}
|
However, if the DB DOES exists but the collection does not, then I get the output colin showed
|
|
I'm not able to reproduce the issue reported, or I'm lacking some information. On master:
mongos> use config
|
switched to db config
|
mongos> db.collection.aggregate([{$collStats: {}}])
|
{ "ns" : "config.collection", "shard" : "config", "host" : "enzo:27010", "localTime" : ISODate("2023-09-26T17:24:47.166Z") }
|
mongos> db.collection.aggregate([ { "$collStats" : { "count" : { } } } ])
|
uncaught exception: Error: command failed: {
|
"ok" : 0,
|
"errmsg" : "PlanExecutor error during aggregation :: caused by :: Unable to retrieve count in $collStats stage :: caused by :: Collection [config.collection] not found.",
|
"code" : 26,
|
"codeName" : "NamespaceNotFound",
|
Now on mongod:
bart:PRIMARY> use config
|
switched to db config
|
bart:PRIMARY> db.collection.aggregate([{$collStats: {}}])
|
{ "ns" : "config.collection", "shard" : "bart", "host" : "enzo:27011", "localTime" : ISODate("2023-09-26T17:28:08.199Z") }
|
bart:PRIMARY> db.collection.aggregate([ { "$collStats" : { "count" : { } } } ])
|
uncaught exception: Error: command failed: {
|
"ok" : 0,
|
"errmsg" : "PlanExecutor error during aggregation :: caused by :: Unable to retrieve count in $collStats stage :: caused by :: Collection [config.collection] not found.",
|
"code" : 26,
|
"codeName" : "NamespaceNotFound",
|
|