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

Repair resets database data file version to 4.5

    • ALL

      Running repairDatabase on a data file version 4.6 database incorrectly sets the data file version on the new database to 4.5 instead of 4.6. This corrupts any existing text/2dsphere indexes, which are built correctly during the repair but then treated as ascending on subsequent document modifications.

      Regression since 2.5.5.

      > db.dropDatabase()
      { "dropped" : "test", "ok" : 1 }
      > db.foo.ensureIndex({a:"text"})
      WriteResult({ "nInserted" : 1 })
      > db.foo.insert({a:"hello world"})
      WriteResult({ "nInserted" : 1 })
      > db.foo.validate().keysPerIndex
      { "test.foo.$_id_" : 1, "test.foo.$a_text" : 2 }
      > db.stats().dataFileVersion
      { "major" : 4, "minor" : 6 }
      > db.repairDatabase()
      { "ok" : 1 }
      > db.stats().dataFileVersion
      { "major" : 4, "minor" : 5 } // incorrect: wrong version
      > db.foo.validate().keysPerIndex
      { "test.foo.$_id_" : 1, "test.foo.$a_text" : 2 } // correct: two text index entries
      > db.foo.insert({a:"hello world"})
      WriteResult({ "nInserted" : 1 })
      > db.foo.validate().keysPerIndex
      { "test.foo.$_id_" : 2, "test.foo.$a_text" : 3 } // incorrect: treated as ascending index (only one key added)
      >
      

      Original description (title "repairDatabase prevents new text and 2dsphere indexes from being created"):

      After running repairDatabase, 2dsphere and text indexes can no longer be created on new collections.

      var myDB = db.getSiblingDB('repaired');
      assert.commandWorked(myDB.dropDatabase());
      
      myDB.one.ensureIndex({h: "2dsphere"});
      myDB.runCommand({repairDatabase: 1});
      myDB.two.ensureIndex({h: "2dsphere"});
      

      Error after the last step:

      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 67,
      		"errmsg" : "Found pre-existing index { v: 1, key: { h: \"2dsphere\" }, name: \"h_2dsphere\", ns: \"repaired.one\", 2dsphereIndexVersion: 2 } with invalid type '2dsphere'. Disallowing creation of new index type '2dsphere'. See http://dochub.mongodb.org/core/index-type-changes"
      	}
      })
      

      Version: b605f98c68a03fd0e65be72f9a22af4f107dee6b

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            kamran.khan Kamran K.
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: