[SERVER-20972] indexStats should not assert if db or collection don't exist Created: 16/Oct/15  Updated: 04/Nov/15  Resolved: 30/Oct/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Diagnostics
Affects Version/s: 3.1.9
Fix Version/s: 3.2.0-rc2

Type: Bug Priority: Major - P3
Reporter: David Golden Assignee: James Wahlin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Major Change
Operating System: ALL
Steps To Reproduce:

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

Participants:

 Description   

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


 Comments   
Comment by Githook User [ 30/Oct/15 ]

Author:

{u'username': u'jameswahlin', u'name': u'James Wahlin', u'email': u'james.wahlin@10gen.com'}

Message: SERVER-20972 indexStats should not assert on missing db or collection
Branch: master
https://github.com/mongodb/mongo/commit/01b3082f3deb7bb6fed0b1e5e2fdc22cbcbb8f5a

Comment by Daniel Pasette (Inactive) [ 16/Oct/15 ]

Definitely want to emulate other agg pipeline behavior for this.

Comment by James Wahlin [ 16/Oct/15 ]

I agree with not creating the collection. Returning 0 results would be in line with what happens when you run a normal aggregation against a non-existent db or collection.

Comment by David Storch [ 16/Oct/15 ]

dan@10gen.com james.wahlin, failing the command with a user-facing error here seems like reasonable behavior. We definitely should not create the collection on the fly, although we could consider changing the behavior to return an empty result set.

Generated at Thu Feb 08 03:55:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.