mongodb-创建索引

在单个field上创建索引,查询时用升序或降序的区别不大。在多个field上创建索引的时候,影响就比较大了。

如果索引中的field是一个array,那么索引就变成了多key索引,多key索引不支持全覆盖查询。

> db.users.createIndex({name:1}); 
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 1,
        "numIndexesAfter" : 2,
        "ok" : 1
}
> db.users.createIndex({name:1,age:1}); 
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 2,
        "numIndexesAfter" : 3,
        "ok" : 1
}
> 
原文地址:https://www.cnblogs.com/abclife/p/5033484.html