查看索引:
db.getCollection('xx').getIndexes();
创建索引:
# 1 代表升序,-1代表降序,name 指定索引名
db.getCollection('xx').createIndex( {"title": 1}, {"name":"idx_xxx"} );
创建复合索引:
db.getCollection('xx').createIndex( {"title": 1, "created_at": -1} );
内嵌字段创建索引:
db.集合名.createIndex( {"字段名.内嵌字段名":1}, {"name":'idx_字段名_内嵌字段名'} )
删除索引:
db.getCollection('xx').dropIndex("idx_xxx");
Ref:https://www.runoob.com/mongodb/mongodb-indexing.html
https://www.cnblogs.com/xuliuzai/p/9965229.html