Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reason for indexing in mongoDB

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about the reasons for indexing in mongoDB. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Index the collection

Mongodb supports embedded attributes to add indexes

Db.agencyTotal.createIndex ({"occurDate": 1})

Add a unique index

Db.agencyTotal.createIndex ({"code": 1}, {"unique": 1})

Parameters of createIndex when indexing

The background Boolean indexing process blocks other database operations, and background can specify that the index is created in the background, that is, adding the "background" optional parameter. The default value for background is false.

Whether the index established by unique Boolean is unique. Specifies that a unique index is created for true. The default value is false.

The name of the name string index. If not specified, MongoDB generates an index name by concatenating the field name and sort order of the index.

Sparse Boolean does not enable indexing for field data that does not exist in the document; this parameter requires special attention that, if set to true, documents that do not contain corresponding fields will not be queried in the index field. The default value is false.

ExpireAfterSeconds integer specifies a value in seconds, completes the TTL setting, and sets the lifetime of the collection.

The version number of the v index version index. The default index version depends on the version that mongod runs when the index is created.

The weights document index weight value, with a value between 1 and 99999, indicates the score weight of the index relative to other index fields.

Default_language string for text indexing, this parameter determines the list of rules for deactivated words and stemming and lexical organs. The default is English

Language_override string for text indexing, this parameter specifies the field name included in the document, the language overrides the default language, and the default value is language.

View Index

Db.agencyTotal.getIndexes ()

View index size

Db.col.totalIndexSize ()

Delete index

Db.col.dropIndex ("index name") above is the reason for indexing in mongoDB. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report