db.collection.ensureIndex()
Definition
mongo
Shell Method
This page documents the mongo
shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.
Deprecated since version 3.0.0: db.collection.ensureIndex()
is now an alias fordb.collection.createIndex()
.
Creates an index on the specified field if the index does notalready exist.
Additional Information
- Use
db.collection.createIndex()
rather thandb.collection.ensureIndex()
to create new indexes. - The Indexes section of this manual for fulldocumentation of indexes and indexing in MongoDB.
db.collection.getIndexes()
to view the specifications ofexisting indexes for a collection.