MongoDB - 索引 (二)使用

索引相关操作


Name Description
db.collection.createIndex() Builds an index on a collection. Use db.collection.ensureIndex().
db.collection.dropIndex() Removes a specified index on a collection.
db.collection.dropIndexes() Removes all indexes on a collection.
db.collection.ensureIndex() Creates an index if it does not currently exist. If the index existsensureIndex() does nothing.
db.collection.getIndexes() Returns an array of documents that describe the existing indexes on a collection.
db.collection.getIndexStats() Renders a human-readable view of the data collected by indexStats which reflects B-tree utilization.
db.collection.indexStats() Renders a human-readable view of the data collected by indexStats which reflects B-tree utilization.
db.collection.reIndex() Rebuilds all existing indexes on a collection.
db.collection.totalIndexSize() Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output.
cursor.explain() Reports on the query execution plan, including index use, for a cursor.
cursor.hint() Forces MongoDB to use a specific index for a query.
cursor.max() Specifies an exclusive upper index bound for a cursor. For use withcursor.hint()
cursor.min() Specifies an inclusive lower index bound for a cursor. For use withcursor.hint()
cursor.snapshot() Forces the cursor to use the index on the _id field. Ensures that the cursor returns each document, with regards to the value of the _id field, only once.
Name Description
dropIndexes Removes indexes from a collection.
compact Defragments a collection and rebuilds the indexes.
reIndex Rebuilds all indexes on a collection.
validate Internal command that scans for a collection’s data and indexes for correctness.
indexStats Experimental command that collects and aggregates statistics on all indexes.
geoNear Performs a geospatial query that returns the documents closest to a given point.
geoSearch Performs a geospatial query that uses MongoDB’s haystack index functionality.
geoWalk An internal command to support geospatial queries.
checkShardingIndex Internal command that validates index on shard key.

Geospatial Query Selectors

Name Description
$geoWithin Selects geometries within a bounding GeoJSON geometry.
$geoIntersects Selects geometries that intersect with a GeoJSON geometry.
$near Returns geospatial objects in proximity to a point.
$nearSphere Returns geospatial objects in proximity to a point on a sphere.

Indexing Query Modifiers

Name Description
$explain Forces MongoDB to report on query execution plans. See explain().
$hint Forces MongoDB to use a specific index. See hint()
$max Specifies an exclusive upper limit for the index to use in a query. Seemax().
$min Specifies an inclusive lower limit for the index to use in a query. See min().
$returnKey Forces the cursor to only return fields included in the index.
$snapshot Forces the query to use the index on the _id field. See snapshot()


后台建立索引 db.people.ensureIndex( { zipcode: 1}, {background: true} ) 

索引相关命令:http://docs.mongodb.org/manual/reference/indexes/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值