cfanbo / cfanbo.github.io

1 stars 0 forks source link

mongodb索引讲解与性能调优 | 学习笔记 #199

Open cfanbo opened 1 year ago

cfanbo commented 1 year ago

https://blog.haohtml.com/archives/12873/

mongodb索引规则基本上与传统的关系库一样,大部分优化MySQL/Oracle/SQLite索引的技巧也适用于mongodb。 一、 为什么用索引: 当查询中用到某些条件时,可以对该键建立索引,以提高查询速度。 如果数据量很多且查询多于更新时,可以用索引提高查询的速度。 二、 索引管理: a) 查询索引: 查询已有索引的明细: 查询索引很简单,比如说需要查询mailaccess数据库中的Mail collection上的索引时: mongo 进入mongo MongoDB shell version: 1.8.1 connecting to: test use mailaccess 进入mailaccess database switched to db mailaccess db.Mail.getIndexes() 查询索引明细 [ { “name” : “id”, “ns” : “mailaccess.Mail”, “key” : { “_id” : 1 }, “v” : 0 }, { “_id” : ObjectId(“4df063ac48857df7ac35c348”), “ns” : “mailaccess.Mail”, “key” : { “user” : 1, “folderId” : 1, “mailfilename” : 1 },