Naming indexes

By default, index names are assigned automatically by MongoDB 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 how MongoDB would have named it ("isbn_1").

 We can view all indexes in our books collection by using db.books.getIndexes(). A fully qualified index name has to be <=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
3.147.53.166