Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-20972

indexStats should not assert if db or collection don't exist

    • Major Change
    • ALL
    • Hide
      MongoDB shell version: 3.0.7
      connecting to: metis.local:50330/test
      Server has startup warnings:
      2015-10-16T11:00:33.815-0400 I CONTROL  [initandlisten]
      2015-10-16T11:00:33.815-0400 I CONTROL  [initandlisten] ** NOTE: This is a development version (3.1.9) of MongoDB.
      2015-10-16T11:00:33.815-0400 I CONTROL  [initandlisten] **       Not recommended for production.
      2015-10-16T11:00:33.815-0400 I CONTROL  [initandlisten]
      2015-10-16T11:00:33.815-0400 I CONTROL  [initandlisten]
      2015-10-16T11:00:33.816-0400 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
      > db.dropDatabase()
      { "dropped" : "test", "ok" : 1 }
      > db.foo.aggregate( { $indexStats:{} })
      assert: command failed: {
              "ok" : 0,
              "errmsg" : "Database not found on index stats retrieval: test",
              "code" : 28804
      } : aggregate failed
      Error: command failed: {
              "ok" : 0,
              "errmsg" : "Database not found on index stats retrieval: test",
              "code" : 28804
      } : aggregate failed
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
          at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
          at (shell):1:8
      2015-10-16T11:01:53.663-0400 E QUERY    Error: command failed: {
              "ok" : 0,
              "errmsg" : "Database not found on index stats retrieval: test",
              "code" : 28804
      } : aggregate failed
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
          at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
          at (shell):1:8 at src/mongo/shell/assert.js:13
      > db.createCollection("foo")
      { "ok" : 1 }
      > db.foo.aggregate( { $indexStats:{} })
      { "name" : "_id_", "host" : "metis.local:50330", "accesses" : { "ops" : NumberLong(0), "since" : ISODate("2015-10-16T15:02:27.991Z") } }
      > db.foo.drop()
      true
      > db.foo.aggregate( { $indexStats:{} })
      assert: command failed: {
              "ok" : 0,
              "errmsg" : "Collection not found on index stats retrieval: test.foo",
              "code" : 28795
      } : aggregate failed
      Error: command failed: {
              "ok" : 0,
              "errmsg" : "Collection not found on index stats retrieval: test.foo",
              "code" : 28795
      } : aggregate failed
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
          at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
          at (shell):1:8
      2015-10-16T11:02:41.830-0400 E QUERY    Error: command failed: {
              "ok" : 0,
              "errmsg" : "Collection not found on index stats retrieval: test.foo",
              "code" : 28795
      } : aggregate failed
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
          at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
          at (shell):1:8 at src/mongo/shell/assert.js:13
      
      Show
      MongoDB shell version: 3.0.7 connecting to: metis.local:50330/test Server has startup warnings: 2015-10-16T11:00:33.815-0400 I CONTROL [initandlisten] 2015-10-16T11:00:33.815-0400 I CONTROL [initandlisten] ** NOTE: This is a development version (3.1.9) of MongoDB. 2015-10-16T11:00:33.815-0400 I CONTROL [initandlisten] ** Not recommended for production. 2015-10-16T11:00:33.815-0400 I CONTROL [initandlisten] 2015-10-16T11:00:33.815-0400 I CONTROL [initandlisten] 2015-10-16T11:00:33.816-0400 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 > db.dropDatabase() { "dropped" : "test", "ok" : 1 } > db.foo.aggregate( { $indexStats:{} }) assert: command failed: { "ok" : 0, "errmsg" : "Database not found on index stats retrieval: test", "code" : 28804 } : aggregate failed Error: command failed: { "ok" : 0, "errmsg" : "Database not found on index stats retrieval: test", "code" : 28804 } : aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5) at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12) at (shell):1:8 2015-10-16T11:01:53.663-0400 E QUERY Error: command failed: { "ok" : 0, "errmsg" : "Database not found on index stats retrieval: test", "code" : 28804 } : aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5) at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12) at (shell):1:8 at src/mongo/shell/assert.js:13 > db.createCollection("foo") { "ok" : 1 } > db.foo.aggregate( { $indexStats:{} }) { "name" : "_id_", "host" : "metis.local:50330", "accesses" : { "ops" : NumberLong(0), "since" : ISODate("2015-10-16T15:02:27.991Z") } } > db.foo.drop() true > db.foo.aggregate( { $indexStats:{} }) assert: command failed: { "ok" : 0, "errmsg" : "Collection not found on index stats retrieval: test.foo", "code" : 28795 } : aggregate failed Error: command failed: { "ok" : 0, "errmsg" : "Collection not found on index stats retrieval: test.foo", "code" : 28795 } : aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5) at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12) at (shell):1:8 2015-10-16T11:02:41.830-0400 E QUERY Error: command failed: { "ok" : 0, "errmsg" : "Collection not found on index stats retrieval: test.foo", "code" : 28795 } : aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5) at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12) at (shell):1:8 at src/mongo/shell/assert.js:13

      Currently, indexStats asserts if the db or collection don't exist. While this may be unlikely in practice, I can see two much more user friendly responses:

      • return an empty result (i.e. 0 documents from the pipeline)
      • create the collection on the fly and return the new id index

            Assignee:
            james.wahlin@mongodb.com James Wahlin
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: