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

createIndexes 'numIndexesAfter' field missing if there are errors

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Index Maintenance
    • ALL
    • Hide
      var coll = db.getSiblingDB('createindexes').validandinvalid;
      coll.drop();
      
      // the second index spec is invalid because it's missing a 'key' field
      var indexes = [{key: {foo: 1}, name: 'first'}, {name: 'second'}];
      
      // attempt to create the indexes
      var res = coll.runCommand('createIndexes', {indexes: indexes});
      printjson(res);
      
      // the first index was created (along with an _id index)
      printjson(coll.getIndexes())
      
      // the result document is missing a numIndexesAfter field even though
      // an index was added
      assert.eq(res.hasOwnProperty('numIndexesAfter'), true);
      
      Show
      var coll = db.getSiblingDB('createindexes').validandinvalid; coll.drop(); // the second index spec is invalid because it's missing a 'key' field var indexes = [{key: {foo: 1}, name: 'first'}, {name: 'second'}]; // attempt to create the indexes var res = coll.runCommand('createIndexes', {indexes: indexes}); printjson(res); // the first index was created (along with an _id index) printjson(coll.getIndexes()) // the result document is missing a numIndexesAfter field even though // an index was added assert.eq(res.hasOwnProperty('numIndexesAfter'), true);
    • Execution Team 2019-06-17

      The 'numIndexesAfter' field is missing from the createIndexes result document when an index build fails – even if a previous index build succeeded within the same command.

      This could be confusing to users who might expect that no indexes were created because there's a 'numIndexesBefore' field but no 'numIndexesAfter' field.

      Example result document:

      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"ok" : 0,
      	"errmsg" : "bad index key pattern {}: Index keys cannot be empty.",
      	"code" : 67
      }
      

      Version: d0135ad0ed90118ad2015283f22b0219c0df3301

            Assignee:
            zach.yam@mongodb.com Zach Yam (Inactive)
            Reporter:
            kamran.khan Kamran K.
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: