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

Don't cache ensureIndex in the shell

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.1
    • Affects Version/s: None
    • Component/s: JavaScript, Shell
    • Labels:
      None
    • Fully Compatible
    • ALL

      It should test getLastError == null rather than ""

      > db.asdf.ensureIndex
      function (keys, options) {
          var name = this._indexSpec(keys, options).name;
          this._indexCache = this._indexCache || {};
          if (this._indexCache[name]) {
              return;
          }
          this.createIndex(keys, options);
          if (this.getDB().getLastError() == "") {
              this._indexCache[name] = true;
          }
      }
      
      > db.asdf.ensureIndex({a:1}); db.getLastError()
      null
      > db.asdf.ensureIndex({a:1}); db.getLastError() == ""
      false
      

      Note that if we fix this we need to make sure that the _indexCache does not persist across calls to db.eval() as the cache won't be invalidated at the necessary times.

      Also, it may be best to just not cache ensureIndex in the shell. If someone runs a script that drops an index, they would expect ensureIndex in an admin shell to rebuild it, even if the shell had been open a while.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: