参考 > 参考 > mongo Shell方法 > 收集方法 > db.collection.ensureIndex()
db.collection.
ensureIndex
(键,选项)¶mongo
壳法
此页面记录了mongo
shell方法,并且
没有引用MongoDB Node.js驱动程序(或任何其他驱动程序)方法。对于相应的MongoDB驱动程序API,请改为参考您特定的
MongoDB驱动程序文档。
从3.0.0版开始不推荐使用:db.collection.ensureIndex()
现在是的别名
db.collection.createIndex()
。
如果索引不存在,则在指定字段上创建索引。
db.collection.createIndex()
而不是
db.collection.ensureIndex()
创建新索引。db.collection.getIndexes()
查看集合的现有索引的规格。