Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-1675

db.GetIndexes should not return an error when the database does not exist

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.6.0-rc0
    • Affects Version/s: None
    • Component/s: mongodump
    • None

      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.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: