On this page本页内容
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.如果索引不存在,则在指定字段上创建索引。
db.collection.createIndex()
rather than db.collection.ensureIndex()
to create new indexes.db.collection.createIndex()
而不是db.collection.ensureIndex()
创建新索引。db.collection.getIndexes()