Indexing Reference
在本页面
mongo Shell 中的索引方法
Name | Description |
---|---|
db.collection.createIndex() | 在集合上构建索引。 |
db.collection.dropIndex() | 删除集合上的指定索引。 |
db.collection.dropIndexes() | 删除集合上的所有索引。 |
db.collection.getIndexes() | 返回描述集合中现有索引的文档数组。 |
db.collection.reIndex() | 重建集合上所有现有的索引。 |
db.collection.totalIndexSize() | 报告集合中索引使用的总大小。在collStats输出的totalIndexSize字段周围提供包装。 |
cursor.explain() | 报告有关游标的查询执行计划。 |
cursor.hint() | 强制 MongoDB 对查询使用特定的索引。 |
cursor.max() | 指定游标的排他上限索引。用于cursor.hint() |
cursor.min() | 指定一个游标的下限值。用于cursor.hint() |
索引数据库命令
Name | Description |
---|---|
createIndexes | 为一个集合构建一个或多个索引。 |
dropIndexes | 从集合中删除索引。 |
compact | 对集合进行碎片整理并重建索引。 |
reIndex | 重建集合上的所有索引。 |
validate | 扫描集合数据和索引是否正确的内部命令。 |
geoNear | 执行地理空间查询,该查询返回最接近给定点的文档。 |
geoSearch | 执行使用 MongoDB 的haystack index功能的地理空间查询。 |
checkShardingIndex | 验证分片键索引的内部命令。 |
地理空间查询 selectors
Name | Description |
---|---|
$geoWithin | 在边界GeoJSON geometry内选择几何。 2dsphere和2d索引支持$geoWithin。 |
$geoIntersects | 选择与GeoJSON几何相交的几何。 2dsphere索引支持$geoIntersects。 |
$near | 返回点附近的地理空间对象。需要地理空间索引。 2dsphere和2d索引支持$near。 |
$nearSphere | 返回球体上某个点附近的地理空间对象。需要地理空间索引。 2dsphere和2d索引支持$nearSphere。 |
索引查询修饰符
Name | Description |
---|---|
$explain | 强制 MongoDB 报告查询执行计划。参见explain()。 |
$hint | 强制 MongoDB 使用特定索引。见hint() |
$max | 指定要在查询中使用的索引的* exclusive *上限。参见max()。 |
$min | 指定要在查询中使用的索引的(含)下限。参见min()。 |
$returnKey | 强制光标仅返回索引中包含的字段。 |