MongoDB索引概述

This is my Fourth MongoDB post, in the first post we looked at how we can install MongoDB as a Windows Service, In the second post we looked at how we could do UPSERTs with MongoDB, In the third post we looked at how to sort results in MongoDB.

This post is about indexing in MongoDB, we are going to take a look at how to create indexes and how to see if the indexes are being used by MongoDB. Every index that you create in MongoDB is a secondary index, this is because MongoDB creates the default _id index for all collections. The _id index is a unique index on the _id field, you cannot delete the index on _id. MongoDB indexes use a B-tree data structure

Besides a regular one field index, you can also create the following indexes in MongoDB

1 Indexes on Embedded Fields

2 Compound Indexes

3 Multikey Indexes

4 Unique Indexes

5 Sparse Indexes

Before you go crazy and start adding indexes on every possible field in your collection, keep in mind that just like in regular databases, the more indexes you have the slower you write operations will be. Every update and insert will be a little slower because the indexes will have to be maintained.

Some limitations: A collection can't have more than 64 indexes.Index keys can't be larger than 1024 bytes. This includes the field value or values, the field name or names, and the namespace.

Let's go take a look at some of these indexes


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-752948/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/301743/viewspace-752948/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值