[SERVER-1627] add createIndexes command Created: 13/Aug/10  Updated: 27/Oct/15  Resolved: 27/Jan/14

Status: Closed
Project: Core Server
Component/s: Admin, Index Maintenance
Affects Version/s: None
Fix Version/s: 2.5.5

Type: Improvement Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-12215 createIndex and ensureIndex do not re... Closed
is depended on by CSHARP-889 Support createdIndexes command Closed
is depended on by JAVA-1080 Support createIndexes command when av... Closed
is depended on by DOCS-2720 document the createIndexes command Closed
is depended on by DRIVERS-132 Use createIndexes command when available Closed
Duplicate
is duplicated by SERVER-7946 Command to build multiple indexes at ... Closed
Related
related to SERVER-12747 createIndexes: 'createdCollectionAuto... Closed
related to DRIVERS-186 Parallel index creation with createIn... Closed
related to SERVER-15754 Allow createIndexes to take "key" fie... Closed
related to SERVER-12967 remove createIndexes 'noChangesMade' ... Closed
is related to SERVER-2441 ensureIndex records arbitrary directi... Closed
is related to SERVER-12542 Add auditing hook to mongos commands ... Backlog
is related to SERVER-12517 Add listIndexes command Closed
is related to SERVER-13240 CreateIndexes: report per index error... Closed
Participants:

 Description   

It seems like it would make sense to have a createIndex command; it would then round out the commands for all index operations (like deleteIndex, reIndex). Conceptually this seems consistent and would remove knowledge about "system.indexes" from within the drivers. Drivers can migrate to this syntax if they see the command available.

This command should take an array of indexes to build in parallel (like compact does). Tools should be changed to use this command so that they are more efficient; then mongorestore can build all indexes at the same time.

Possible format, which will be expanded in the next months:

>db.coll.runCommand("createIndexes", {ensure:true ,indexes: 
  [
    {keys:{}, option1:.., option2:...},
    {keys:{}, option1:.., option2:...}
  ]})
{ ok:1.0, result: 
  { millis: ###,
    indexes: [ {status:"built/failed" <, nkeys: ##, millis: ###, nscannedObjects: ###, stats...>} ]
}}

The "indexes" field should also take a single doc, instead of an array, for simplicity.



 Comments   
Comment by Kamran K. [ 28/Feb/14 ]

derick: The 'noChangesMade' issue is filed as SERVER-12967.

Comment by Derick Rethans [ 12/Feb/14 ]

Can somebody please document what the correct command argument structure is?

I also would like to point out that:

"noChangesMade" : true,

Is a bit awkward. It makes much more sense to use:

"changesMade" : false,

Comment by Githook User [ 29/Jan/14 ]

Author:

{u'name': u'Dan Pasette', u'email': u'dan@10mongodb.com'}

Message: SERVER-1627 remove create_indexes.js from sharding_passthrough
Branch: master
https://github.com/mongodb/mongo/commit/957da5dac2722480de985d117cd366ba492f5d7b

Comment by Githook User [ 27/Jan/14 ]

Author:

{u'username': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: SERVER-1627: createIndexes command
Branch: master
https://github.com/mongodb/mongo/commit/4ae262e2715092700e8fab73eb0b2bea1a119a3b

Comment by Daniel Pasette (Inactive) [ 22/Jan/14 ]

derick, same thing you are doing for the new user manipulation commands.
jmikola@gmail.com, ensureIndex is just a shell helper which in turn calls createIndex, which in turn directly inserts into system.indexes. The name is more consistent with other DDL options in the server and intuitive for most users.

Comment by Jeremy Mikola [ 13/Jan/14 ]

Assuming this behaves the same as ensureIndex but handles multiple indexes, shouldn't it be named ensureIndexes for consistency?

Comment by Derick Rethans [ 08/Jan/14 ]

"Drivers can migrate to this syntax if they see the command available."

How do we see whether this command is available?

Comment by Eliot Horowitz (Inactive) [ 31/Jan/11 ]

This should check for valid index patterns as well.
i.e. should reject

{ x : "abc" }
Generated at Thu Feb 08 02:57:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.