[SERVER-26726] Check number of arguments for createIndex() and throw error if more than two arguments Created: 21/Oct/16  Updated: 04/Mar/21  Resolved: 24/Aug/20

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.9
Fix Version/s: 4.7.0, 4.2.10, 4.4.2, 4.0.21, 3.6.21

Type: Improvement Priority: Major - P3
Reporter: Manan Shah Assignee: Nikita Lapkov (Inactive)
Resolution: Done Votes: 5
Labels: move-sa, neweng, qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Documented
is documented by DOCS-13846 Investigate changes in SERVER-26726: ... Closed
Duplicate
is duplicated by SERVER-38592 A malformed createIndex doesn't gener... Closed
Backwards Compatibility: Minor Change
Backport Requested:
v4.4, v4.2, v4.0, v3.6
Sprint: Query 2020-08-24, Query 2020-09-07
Participants:
Case:

 Description   

If a third argument is passed to the ensureIndex() with valid options, then the behavior is to ignore the third argument instead of an error. So for example, if I execute the following

db.myColl.ensureIndex( { my_date: 1}, {expireAfterSeconds: 2678400},{background: true, sparse: true } ) 

the third argument which is critical to the purpose of this index build is completely ignored and the index is built in the foreground with no sparse option. This can lead to catastrophic events if myColl is very large and foreground index was not a choice. Can this be fixed so a user is not punished for accidentally passing the critical options as a third argument in the index build? The version we tried this is 3.2.9



 Comments   
Comment by Githook User [ 11/Sep/20 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-26726 Check number of arguments for createIndex, createIndexes and ensureIndex shell commands

(cherry picked from commit be07da4bd6dd394947236857f5510a7ba9c3b0a4)
Branch: v4.4
https://github.com/mongodb/mongo/commit/df22315f799b9440941539e288caf9a53b8ecb7c

Comment by Githook User [ 09/Sep/20 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-26726 Check number of arguments for createIndex, createIndexes and ensureIndex shell commands

(cherry picked from commit be07da4bd6dd394947236857f5510a7ba9c3b0a4)
Branch: v4.0
https://github.com/mongodb/mongo/commit/c209bf2d265b59765ee07765654a257abfe76a2a

Comment by Githook User [ 09/Sep/20 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-26726 Check number of arguments for createIndex, createIndexes and ensureIndex shell commands

(cherry picked from commit be07da4bd6dd394947236857f5510a7ba9c3b0a4)
Branch: v4.2
https://github.com/mongodb/mongo/commit/cc8e51c57669e792ac025660428dbfd6a29e09dd

Comment by Githook User [ 09/Sep/20 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-26726 Check number of arguments for createIndex, createIndexes and ensureIndex shell commands

(cherry picked from commit be07da4bd6dd394947236857f5510a7ba9c3b0a4)
Branch: v3.6
https://github.com/mongodb/mongo/commit/d7a970f6b1d87fc4c3754cd53f0ea4ea6bd7caf6

Comment by Manan Shah [ 21/Aug/20 ]

Thanks for the update.

Comment by Nikita Lapkov (Inactive) [ 21/Aug/20 ]

Hey! To fix this issue we have added validation of number of arguments in shell functions createIndex, createIndexes and ensureIndex. Changes will be backported to versions 4.4, 4.2, 4.0 and 3.6

Comment by Githook User [ 21/Aug/20 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-26726 Check number of arguments for createIndex, createIndexes and ensureIndex shell commands
Branch: master
https://github.com/mongodb/mongo/commit/be07da4bd6dd394947236857f5510a7ba9c3b0a4

Comment by Manan Shah [ 12/May/17 ]

Is there an update here?

Comment by Manan Shah [ 21/Oct/16 ]

Thanks. That would be a reasonable request.

Comment by Ramon Fernandez Marina [ 21/Oct/16 ]

If I understand correctly, this is a "feature" in JavaScript, so I'm repurposing this as an improvement request and sending it to the Platforms team to evaluate whether the shell can be improved here to protect against this case.

Thanks,
Ramón.

Generated at Thu Feb 08 04:13:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.