db.collection.ensureIndex()

On this page本页内容

Definition定义

db.collection.ensureIndex(keys, options)

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

Deprecated since version 3.0.0:自3.0.0版起已弃用:db.collection.ensureIndex() has been replaced by db.collection.createIndex().已被db.collection.createIndex()替换。

Creates an index on the specified field if the index does not already exist.如果索引不存在,则在指定字段上创建索引。

Additional Information其他信息