...
The current behavior is for mongod to fail to start. This is unacceptable because it doesn't allow for any user remediation to drop invalid view definitions.
kyle.suarez commented on Wed, 17 Aug 2016 18:18:02 +0000: I'm marking this as "Documentation changes needed" to ensure that we document the behavior of the server in the event a user manually tampers with system.views. xgen-internal-githook commented on Wed, 17 Aug 2016 18:15:38 +0000: Author: {u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'} Message: SERVER-25492 mongod gracefully handles invalid views on startup Allows mongod to be (re)started, even in the presence of invalid view definitions in system.views. View operations will fail until the offending views are removed. Branch: master https://github.com/mongodb/mongo/commit/4eaa5aafce9457ed0f90c5099eee45ab12e9c3a3 geert.bosch commented on Wed, 17 Aug 2016 11:10:04 +0000: Discussion with schwerin led us to use an explicit system.views collection, but not prohibit direct access as trying to make exceptions based on recovery-state, internal vs external client etc tends to get messy/buggy. Direct access can be limited instead through the usual authorization mechanisms where needed. It is the case today that you can get your system in bad state by directly writing to system collections. kyle.suarez commented on Tue, 9 Aug 2016 15:01:13 +0000: pasette, that was our original intention, but because of the way the replication system works, geert.bosch determined it would not be possible to prohibit inconsistencies in system.views. dan@10gen.com commented on Mon, 8 Aug 2016 21:32:09 +0000: Is there any reason to allow direct inserts into system.views? Let's turn this off at the source.
python buildscripts/resmoke.py --executor=no_server bad_view.js bad_view.js var dbpath = MongoRunner.dataPath; resetDbpath(dbpath); var options = { dbpath: dbpath, noCleanData: true, setParameter: "enableViews=1", }; var conn = MongoRunner.runMongod(options); assert.neq(null, conn, "mongod failed to start up with options: " + tojson(options)); // Insert directly into the system.views collection to bypass the validation that the // "create" command performs. assert.writeOK(conn.getDB("test").system.views.insert({pipeline: "bad type"})); // Try to restart the mongod. MongoRunner.stopMongod(conn); conn = MongoRunner.runMongod(options); assert.neq(null, conn, "mongod failed to start up with options: " + tojson(options)); Output [js_test:bad_view] 2016-08-08T17:05:23.381-0400 d20011| 2016-08-08T17:05:23.380-0400 I STORAGE [initandlisten] exception in initAndListen: 182 invalid view definitions reading 'test.system.views', terminating ... [js_test:bad_view] 2016-08-08T17:05:23.523-0400 2016-08-08T17:05:23.522-0400 E QUERY [thread1] Error: [null] != [null] are equal : mongod failed to start up with options: { [js_test:bad_view] 2016-08-08T17:05:23.523-0400 "dbpath" : "/data/db/job0/mongorunner/", [js_test:bad_view] 2016-08-08T17:05:23.524-0400 "noCleanData" : true, [js_test:bad_view] 2016-08-08T17:05:23.524-0400 "setParameter" : "enableViews=1" [js_test:bad_view] 2016-08-08T17:05:23.524-0400 } : [js_test:bad_view] 2016-08-08T17:05:23.524-0400 doassert@src/mongo/shell/assert.js:15:14 [js_test:bad_view] 2016-08-08T17:05:23.524-0400 assert.neq@src/mongo/shell/assert.js:128:5 [js_test:bad_view] 2016-08-08T17:05:23.525-0400 @bad_view.js:20:1 [js_test:bad_view] 2016-08-08T17:05:23.525-0400 failed to load: bad_view.js