db.collection.ensureIndex()

Definition

  • db.collection.ensureIndex(keys, options)

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