Database Manual / Indexes

Indexing Reference索引参考

Indexing Methods in mongoshmongosh中的索引方法

Name名称Description描述
db.collection.createIndex()Builds an index on a collection.在集合上构建索引。
db.collection.dropIndex()Removes a specified index on a collection.删除集合上的指定索引。
db.collection.dropIndexes()Removes all indexes on a collection.删除集合上的所有索引。
db.collection.getIndexes()Returns an array of documents that describe the existing indexes on a collection.返回描述集合上现有索引的文档数组。
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.collStats输出的totalIndexSize字段提供包装。
cursor.explain()Reports on the query execution plan for a cursor.关于游标的查询执行计划的报告。
cursor.hint()Forces MongoDB to use a specific index for a query.强制MongoDB对查询使用特定索引。
cursor.max()Specifies an exclusive upper index bound for a cursor. 指定游标的独占索引上限。For use with cursor.hint()cursor.hint()一起使用
cursor.min()Specifies an inclusive lower index bound for a cursor. For use with cursor.hint()指定游标的包含性下限索引。与cursor.hint()一起使用

Indexing Database Commands索引数据库命令

Name名称Description描述
createIndexesBuilds one or more indexes for a collection.为集合构建一个或多个索引。
dropIndexesRemoves 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.扫描集合的数据和索引是否正确的内部命令。
setIndexCommitQuorumChanges the minimum number of data-bearing members (i.e commit quorum), including the primary, that must vote to commit an in-progress index build before the primary marks those indexes as ready.更改数据承载成员的最小数量(即提交法定人数),包括主成员,在主成员将这些索引标记为就绪之前,必须投票提交正在进行的索引构建

Geospatial Query Selectors地理空间查询选择器

Name名称Description描述
$geoWithinSelects geometries within a bounding GeoJSON geometry. 在边界GeoJSON几何图形中选择几何图形。The 2dsphere and 2d indexes support $geoWithin.2dsphere2d索引支持$geoWithin
$geoIntersectsSelects geometries that intersect with a GeoJSON geometry. 选择与GeoJSON几何图形相交的几何图形。The 2dsphere index supports $geoIntersects.2dsphere索引支持$geoIntersects
$nearReturns geospatial objects in proximity to a point. Requires a geospatial index. 返回点附近的地理空间对象。需要地理空间索引。The 2dsphere and 2d indexes support $near.2dsphere2d索引支持$near
$nearSphereReturns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. 返回球体上某点附近的地理空间对象。需要地理空间索引。The 2dsphere and 2d indexes support $nearSphere.2dsphere2d索引支持$nearSphere