当前位置:网站首页>Mongodb create index
Mongodb create index
2022-07-28 18:22:00 【Water and moon are clear and bright】
grammar :
db.collection.createIndex(keys, options)
Key: The value is the index field that you want to create
1: Specifies that the index is created in ascending order
-1: Index is created in descending order
Example :
db.col.createIndex({"title":1})
Create composite index :
Set to use multiple fields to create an index ( A relational database is called a composite index )
Example :
>db.test.createIndex({"title":1,"description":-1})
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. |
Creating indexes in the background :
By adding when the index is created background:true The option to , Let the creation work execute in the background
Example :
db.values.createIndex({open: 1, close: 1}, {background: true})
边栏推荐
- Delete the last page of word document
- Busybox latest version (busybox APK)
- Power adapter global definition
- [reading notes] - 2 learn machine learning classification through naive Bayesian model
- Seven steps, in-depth interpretation of data meaning
- How to sharpen a knife simply by yourself
- Five key considerations for network security budget planning in 2023
- 如何简简单单地自己动手磨刀
- 任正非最新发声:美国政治家希望华为死,求生欲使华为振奋起来
- Application of Internet of things in smart city
猜你喜欢

Flutter:异常处理

Fluent: exception handling

信号源原理简介

Leetcode--45. jumping game II (greed)

Digital filter (VI) -- design FIR filter

Openmv (III) -- get camera pictures in real time

About the difference between root and alias under localization

Introduction to USB type-C PD fast charging

示波器探头详解

Connect other computers to local MySQL
随机推荐
频谱分析仪的性能参数
The diversion between video number and official account is convenient and considerable
Nearly 200000 people watched a live calligraphy video
华为中兴在英国败诉,不交专利授权费将被禁售!
视频号7天销售额超百万
Temporary URL
Sales of video related products increased by 88%
Openmv (II) -- ide installation and firmware download
Tips -- solve the problem of no module named matlab.engine
Iptables防火墙详细介绍
vmware虚拟机联网设置(win10自带虚拟机安装win7)
Answer questions about the pixel, resolution and size of the picture, as well as the display size of the monitor.
Experience 5 minutes to develop wechat apps
The difference between probability function p (x), probability distribution function f (x) and probability density function f (x)
About the difference between root and alias under localization
【干货】如何建立支持和产品之间的密切关系?
"Cloud strategy" will become an important pillar of enterprise digital transformation
Advanced Design System(ADS)2009 射频仿真入门
Xcode packaging IPA configuration manual configuration certificate
The best implementation of horizontal listview -- recycleview