Second parameter of db.col.createIndex

Could someone explain to me exactly what this index means or implies?

db.x.createIndex( { “user.login”: 1, “”: -1 }, “myIndex” )

The second parameter “myIndex” catches my attention and I don’t understand where to find this kind of thing in the mongo guide. Any reference?

Thank you!

The first parameter is specifying the shape of the compound index. First, by sorting embedded field user.login in ascending (1) order, and then by sorting in descending (-1) order within the context of user.login. The field order and the direction ( 1 or -1) of sort is important in a compound index.

The second parameter to the createIndex function ( is the name of the index.


1 Like

Thank you very much, I really couldn’t find the logic, I already read “options for all index types” → name