Naming indexes

By default, index names are assigned by MongoDB automatically, based on the fields indexed and the direction of the index (1, -1). If we want to assign our own name, we can do so at creation time:

> db.books.createIndex( { isbn: 1 }, { name: "international_standard_book_number_index" } )

Now, we have a new index called international_standard_book_number_index, instead of what MongoDB would have named it ("isbn_1").

We can view all of the indexes in our books collection by using db.books.getIndexes(). A fully qualified index name has to be less than or equal to 128 characters. That also includes database_name, collection_name, and the dots separating them.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset