[SERVER-21779] db.runCommand() should return error if second argument is invalid Created: 06/Dec/15  Updated: 06/Dec/17  Resolved: 28/Jun/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.0.7
Fix Version/s: 3.5.10

Type: Improvement Priority: Major - P3
Reporter: Ankit Kakkar Assignee: Benety Goh
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-769 Validate top-level & index spec field... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Team,

If we try to create index using misplaced background configuration, MongoDB should be able to validate and report back the error. For example, if I run following command, server doesn't tells me that background is placed wrong and instead runs the indexing in foreground:

db.runCommand({
	createIndexes: "exampleIndex",
	indexes: [{
		key: {
			a: 1,
			b: 1,
			"c": 1
		},
		name: "a_1_b_1_c_1"
	},
	{
		key: {
			a: 1,
			b: 1,
			c: 1,
			"d": 1,
			e: 1
		},
		name: "a_1_b_1_c_1_d_1_e_1"
	}]
},{ background: true })

Note that the background: true is not present per index level but is defined at global level.



 Comments   
Comment by Githook User [ 28/Jun/17 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-21779 validate DB.runCommand(commandObjOrName, extraKeys) arguments.

When the command object is passed in as the first argument, any non-empty 'extraKeys'
object will return an error.
Branch: master
https://github.com/mongodb/mongo/commit/a72d5e357fc0e8b31e705cba539762cd79093773

Comment by Githook User [ 28/Jun/17 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-21779 fixed misplaced write concern argument to collection drop command
Branch: master
https://github.com/mongodb/mongo/commit/8da913c726c7ce11a571c6600e08e0c27355b2cd

Comment by J Rassi [ 07/Dec/15 ]

The issue you're running into here is with the db.runCommand() shell helper, not with the createIndexes command. It is invalid to pass a non-empty second argument to the db.runCommand() shell helper if the first argument has a non-string type. The shell helper should return an error if this happens, instead of silently ignoring the second argument.

Updated ticket summary accordingly.

See also linked ticket SERVER-769.

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