[SERVER-12855] createIndexes 'numIndexesAfter' field missing if there are errors Created: 24/Feb/14  Updated: 14/Jun/19  Resolved: 14/Jun/19

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.6.0-rc0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kamran K. Assignee: Zach Yam (Inactive)
Resolution: Done Votes: 0
Labels: 26qa, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-13240 CreateIndexes: report per index error... Closed
Tested
Operating System: ALL
Steps To Reproduce:

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);

Sprint: Execution Team 2019-06-17
Participants:

 Description   

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



 Comments   
Comment by Zach Yam (Inactive) [ 14/Jun/19 ]

When this command fails, it does not report numIndexesAfter because no indexes would have been built. 

 

This command has changed such that both indexes are built at the same time. If one of them fails, then both of them fail

Comment by Zach Yam (Inactive) [ 14/Jun/19 ]

This is what the output looks like:

 

{ "ok" : 0, "errmsg" : "Error in specification { name: \"second\" } :: caused by :: The 'key' field is a required property of an index specification", "code" : 9, "codeName" : "FailedToParse" }

 

Comment by Dianna Hohensee (Inactive) [ 29/May/19 ]

We should determine whether this behavior still exists or was modified in the last 5 years.

Comment by Daniel Pasette (Inactive) [ 02/Mar/14 ]

Also noticed that numIndexesBefore isn't returned in some cases, which could be fixed by setting it earlier.

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