MongoDB极简教程 · Mongo · NoSQLMongoDB指南

mongodb索引及查询优化分析

2017-10-27  本文已影响118人  liudongdong

Mongodb索引及查询优化分析

创建索引

    db.collection.createIndex(keys, options)

唯一(_id)索引

单键索引

复合索引

多键索引

稀疏索引

    db.collection.createIndex({“FieldName”:1},{“sparse”:true})

局部索引(Partial Index)

    db.collection.createIndex(
    {“FieldName”: 1/-1,…”FieldNameN”: 1/-1},
    {“partialFilterExpression”:{partialFilterExpression }})
    
    db.contacts.createIndex(
    { name: 1 },
    { partialFilterExpression: { name: { $exists: true } } }
    )

TTL(过期)索引

全文索引

地理空间索引

哈希索引

查询性能分析

    db.collection.find({}).explain("queryPlanner"/"executionStats"/"allPlansExecution")
    db.file.createIndex({'tag.self':1})
    db.file.find({'tag.self':{$in:['node']}}).explain("executionStats")

性能指标

总结:

上一篇 下一篇

猜你喜欢

热点阅读