当前位置:网站首页>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})
边栏推荐
- ADS仿真 之 交流仿真和S参数仿真示例
- Video number from 2-3 games per week to 3 games per day
- The video number is more like a official account of version 2.0
- iptables防火墙端口规则配置
- Digital filter (IV) -- converting analog filter into digital filter
- Power adapter global definition
- 体验5分钟开发微信小程序
- solidity转账函数的实现(基于transfer)
- Import the database backup of MySQL 8 into MySQL 5
- busybox最新版(busybox apk)
猜你喜欢

频谱仪原理简介二

Digital filter (VI) -- design FIR filter

Personal production: ad library, component library, packaging library and 3D model, free of charge

个人制作:AD库、元件库、封装库及3D模型,免费

Openmv (V) -- STM32 to realize face recognition

Flutter:异常处理

Openmv (VI) -- STM32 realizes object recognition and handwritten digit recognition

Centos8 creates wordpress+mysql error reports according to the official website of docker

Tips -- understanding of the physical meaning of convolution

矢量网络分析仪(矢网)的校准
随机推荐
Dormant for two years! Lingsheng technology's first aiot chip released: Samsung 11nm process, integrated NPU core!
Internet intelligence, how to define the next generation network transformation
USB Type-C 详解
业绩增长强劲!闻泰科技上半年净利17亿元,同比暴增767.19%!
个人制作:AD库、元件库、封装库及3D模型,免费
busybox最新版(busybox apk)
Experience 5 minutes to develop wechat apps
The diversion between video number and official account is convenient and considerable
.net swagger
Categories with good sales volume on the video Number
LeetCode79题 方法一:深度搜索
Centos8 creates wordpress+mysql error reports according to the official website of docker
After CentOS uses docker to run mysql, the remote connection needs to open the port
[untitled]
连线:谁拥有未来的艺术?OpenAI允许Dall-E用户将作品商用化,目前而言
视频号一条视频播放2.6亿
[dry goods] how to establish a close relationship between support and products?
频谱仪原理简介一
电源适配器 全球定义
ADS仿真 之 直流仿真示例