db.GetIndexes does not return an error when the collection does not exist, it should also not return an error when the database does not exist. With this change GetIndexes will match the behavior of getIndexesPre28, also it seems to make sense that it we're ignoring "no collection" errors than we should also ignore "no database" errors.
MongoDB 3.0 and up always returns error code 26 when the database/collection does not exist:
$ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.0.0 WARNING: shell and server versions do not match > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26 } > db.createdb.insert({}) WriteResult({ "nInserted" : 1 }) > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26 } > bye $ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.0.14 WARNING: shell and server versions do not match > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no database", "code" : 26 } > db.createdb.insert({}) WriteResult({ "nInserted" : 1 }) > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26 } > bye $ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.2 Server has startup warnings: 2017-03-03T10:44:52.603-0800 I CONTROL [initandlisten] 2017-03-03T10:44:52.603-0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-03-03T10:44:52.603-0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-03-03T10:44:52.603-0800 I CONTROL [initandlisten] > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no database", "code" : 26, "codeName" : "NamespaceNotFound" } > db.createdb.insert({}) WriteResult({ "nInserted" : 1 }) > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26, "codeName" : "NamespaceNotFound" } > ^C bye $ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.2 Server has startup warnings: 2017-03-03T10:45:31.411-0800 I CONTROL [initandlisten] 2017-03-03T10:45:31.411-0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-03-03T10:45:31.411-0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-03-03T10:45:31.411-0800 I CONTROL [initandlisten] > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no database", "code" : 26, "codeName" : "NamespaceNotFound" } > db.createdb.insert({}) WriteResult({ "nInserted" : 1 }) > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26, "codeName" : "NamespaceNotFound" } > bye $ mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.5.3-79-gb94dd91 WARNING: shell and server versions do not match Server has startup warnings: 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] ** NOTE: This is a development version (3.5.3-79-gb94dd91) of MongoDB. 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] ** Not recommended for production. 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-03-03T10:48:32.806-0800 I CONTROL [initandlisten] MongoDB Enterprise > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no database", "code" : 26, "codeName" : "NamespaceNotFound" } MongoDB Enterprise > db.createdb.insert({}) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise > db.runCommand({"listIndexes": "test"}) { "ok" : 0, "errmsg" : "no collection", "code" : 26, "codeName" : "NamespaceNotFound" } MongoDB Enterprise > ^C bye
This change would only affect mongodump as it's the only tool that calls db.GetIndexes.