当前位置:网站首页>Mongodb index -index
Mongodb index -index
2022-06-13 02:56:00 【Knowing and knowing】
MongoDB Indexes
1. summary
- Index support in MongoDB Efficiently execute queries in . If there is no index ,MongoDB A full set scan must be performed , That is, scanning every document in the collection , To select and query statements
Matching documents . The query efficiency of scanning the whole collection is very low , Especially when dealing with large amounts of data , Queries can take tens of seconds or even minutes , This is right and wrong for the performance of the website Often fatal . - If the query has an appropriate index ,MongoDB You can use this index to limit the number of documents that must be checked .
- An index is a special data structure , It stores a small portion of the collection dataset in an easy to traverse form . An index stores the values of a particular field or group of fields , Sort by field value . Row of index entries
Order supports effective equality matching and range based query operations . Besides ,MongoDB You can also use the sort in the index to return the sort result .
Official document :https://docs.mongodb.com/manual/indexes/
2. Type of index
- Single field index
MongoDB Supports the creation of user-defined ascending order on a single field of a document / descending index , It's called a single field index (Single Field Index).
For single field indexing and sorting operations , Sort order of index keys ( In ascending or descending order ) Not important , because MongoDB The index can be traversed in any direction . - Composite index
MongoDB It also supports user-defined indexes for multiple fields , Composite index (Compound Index). The order of the fields listed in a composite index is significant . for example , If the composite index is from { userid: 1, score: -1 } form , Then the index first presses userid Positive sequence sort , then
At every userid Within the value of , Press... Again score Reverse sort . - Other indexes
Geospatial index (Geospatial Index), Text index (Text Indexes), Hash index (Hashed Indexes)
3. Index management operations
View index
explain :
Returns an array of all indexes in a collection .
grammar :
db.collection.getIndexes()
Tips : The syntax command is required to run MongoDB 3.0+
Index creation
explain :
Create an index on a collection .
grammar :
db.collection.createIndex(keys, options)
createIndex() Receive optional parameters , The list of optional parameters is as follows :
| Parameter | Type | Description |
|---|---|---|
| background | Boolean | The indexing process blocks other database operations ,background You can specify backchannel mode to create indexes , That is, increase “background” Optional parameters . “background” The default value is false. |
| unique | Boolean | Is the index created unique . Designated as true Create unique index . The default value is false. |
| name | string | Name of index . If not specified ,MongoDB Generates an index name by concatenating the field name of the index and the sort order . |
| dropDups | Boolean | 3.0+ Version obsolete . Whether to delete duplicate records when establishing a unique index , Appoint true Create unique index . The default value is false. |
| sparse | Boolean | Indexes are not enabled for field data that does not exist in the document ; This parameter requires special attention , If set to true Words , Documents that do not contain corresponding fields are not queried in index fields .. The default value is false. |
| expireAfterSeconds | integer | Specifies a value in seconds , complete TTL Set up , Sets the lifetime of the collection . |
| v | index version | The version number of the index . The default index version depends on mongod The version that runs when the index is created . |
| weights | document | Index weight , Values in 1 To 99,999 Between , Represents the score weight of the index relative to other index fields . |
| default_language | string | For text index , This parameter determines the list of stop words and the rules for the word stem and lexicon . Default to English |
| language_override | string | For text index , This parameter specifies the name of the field to be included in the document , The language overrides the default language, The default value is language. |
Index removal
explain : You can remove the specified index , Or remove all indexes
One 、 Specifies the removal of the index
grammar :
db.collection.dropIndex(index)
Parameters :
| Parameter | Type | Description |
|---|---|---|
| index | string or document | Specify the index to delete . The index can be specified by index name or index specification document . To delete the text index , Please specify the index name . |
Two 、 Removal of all indexes
grammar :
db.collection.dropIndexes()
边栏推荐
- [thoughts in the essay] mourn for development technology expert Mao Xingyun
- Detailed explanation of UCI datasets and their data processing (with 148 datasets and processing codes attached)
- Surpass the strongest variant of RESNET! Google proposes a new convolution + attention network: coatnet, with an accuracy of 89.77%!
- JS deconstruction assignment
- Five old code farmers, program life review: peace of mind is not the place to go
- Radio design and implementation in IVI system
- House raiding
- Ijkplayer source code - audio playback
- JS merge multiple string arrays to maintain the original order and remove duplicates
- Linked list: reverse linked list
猜你喜欢

Introduction and download of common data sets for in-depth learning (with network disk link)

Why does it feel that most papers still use RESNET as the backbone network rather than densenet?

Linked list: palindrome linked list

Keil去掉烦人的ST-Link更新提示

Scala implements workcount
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)

Keil removes annoying st link update tips

二叉树初始化代码

Vs Code modify default terminal_ Modify the default terminal opened by vs Code

Prometheus node_exporter安装并注册为服务
随机推荐
nn. Conv2d and nn Convtranspose2d differences
Opencv 08 demonstrates the effect of opening and closing operations of erode, dilate and morphological function morphologyex.
[data analysis and visualization] key points of data drawing 6- too many data groups
【 enregistrement pytorch】 paramètre et tampon des variables pytorch. Self. Register Buffer (), self. Register Paramètre ()
Opencv 9 resize size change rotate rotate blur mean (blur)
Detailed explanation of data processing in machine learning (I) -- missing value processing (complete code attached)
Welcome to blog navigation
wx. Createselectorquery() gets the usage of DOM nodes in components
Simple use of leaflet - offline map scheme
Hash table: the time complexity of insert, delete and random access is O (1)
mysql索引
【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()
Wechat applet switch style rewriting
Hash table: least recently used cache
Uni app Foundation
Hash table: whether alien languages are sorted
Why does it feel that most papers still use RESNET as the backbone network rather than densenet?
How did you spend your winter vacation perfectly?
js多种判断写法
Stack: daily temperature