MongoDB - 索引 (二)使用

来源:互联网 发布:数据标准化处理的方法 编辑:程序博客网 时间:2024/06/05 08:00
索引相关操作


NameDescriptiondb.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.
NameDescriptiondropIndexesRemoves indexes from a collection.compactDefragments a collection and rebuilds the indexes.reIndexRebuilds all indexes on a collection.validateInternal command that scans for a collection’s data and indexes for correctness.indexStatsExperimental command that collects and aggregates statistics on all indexes.geoNearPerforms a geospatial query that returns the documents closest to a given point.geoSearchPerforms a geospatial query that uses MongoDB’s haystack index functionality.geoWalkAn internal command to support geospatial queries.checkShardingIndexInternal command that validates index on shard key.

Geospatial Query Selectors

NameDescription$geoWithinSelects geometries within a bounding GeoJSON geometry.$geoIntersectsSelects geometries that intersect with a GeoJSON geometry.$nearReturns geospatial objects in proximity to a point.$nearSphereReturns geospatial objects in proximity to a point on a sphere.

Indexing Query Modifiers

NameDescription$explainForces MongoDB to report on query execution plans. See explain().$hintForces MongoDB to use a specific index. See hint()$maxSpecifies an exclusive upper limit for the index to use in a query. Seemax().$minSpecifies an inclusive lower limit for the index to use in a query. See min().$returnKeyForces the cursor to only return fields included in the index.$snapshotForces 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
原创粉丝点击