当前位置:网站首页>Mongodb index unique
Mongodb index unique
2022-06-10 19:49:00 【51CTO】
Index unique assurez - vous que le champ index ne stocke pas les valeurs dupliquées;C'est - à - dire forcer le caractère unique du champ index.Par défaut,MongoDBLors de la création de la collection àidCréer un index unique sur le champ.
DeMongodb4.2Début de la version,La version de compatibilité fonctionnelle est4.2(Ou plus),MongoDBUn nouveau format interne a été utilisé pour les index uniques,C'est ce qui s'est passé avec les premiersMongoDBVersion incompatible,Le nouveau format s'applique aux index uniques existants ainsi qu'aux nouveaux/Index unique reconstruit.
1、Mise à jourmongodbUn indice de valeur nulle s'est produit dans le champ document
db.version()
4.2.18
1.2、Voir l'index des collections:
1.3、 C'est ce que disent les documents officiels : Pour consulter les documents officiels, cliquez sur le texte
Si un document n'a pas de valeur pour le champ index dans un index unique , L'index stockera alors une valeur vide Pour ce document . En raison de contraintes uniques ,MongoDB Un seul document sans champ d'index est autorisé . Si plus d'un document n'a pas de valeur pour le champ index ou s'il manque un champ index , La construction de l'index échouera en raison d'une erreur de clé dupliquée .
Fonctionnement: Supprimer les documents qui n'ont pas de champs d'index uniques ,Mise à jour réussie.
2、Index unique:
Peut être créé en un seul champ , Créer une commande d'index unique db.collection.createIndex() Oui.unique Set totrue
db.collection.createIndex( <key and index type specification>, { unique: true } )
Insérer une donnée
Insertion répétée d'un champ unique
Insérer des données qui ne contiennent pas de champs d'index uniques
Vous pouvez également créer un index unique composé
Un autre exemple est, Considérez une collection avec les documents suivants
{ _id: 1, a: [ { loc: “A”, qty: 5 }, { qty: 10 } ] }
db.collection.createIndex( { “a.loc”: 1, “a.qty”: 1 }, { unique: true } )
Un index unique permet d'insérer les documents suivants dans la collection ,
Parce que la paire d'index a.locEta.qty La combinaison de valeurs impose l'unicité , Les données suivantes ont donc été insérées avec succès
边栏推荐
- DDD landing practice repeat record of theoretical training & Event storm
- 如何在VR全景作品中添加独立热点?
- Nature Biotechnol | 李家洋/余泓团队利用平铺删除策略打破性状连锁,突破水稻产量瓶颈
- 金融行业的密钥及加密机制
- Tencent libco collaboration open source library source code analysis full series summary blog
- 【C语言】一不小心写出bug?凡人教你如何写出好代码【详解vs中调试技巧】
- 騰訊Libco協程開源庫 源碼分析(二)---- 柿子先從軟的捏 入手示例代碼 正式開始探究源碼
- 深入理解LightGBM
- frp reverse proxy
- Summary of "performance test" of special test
猜你喜欢

2022 software test interview strategy for the strongest version of fresh students to help you get directly to the big factory

【 Web 】 page d'accueil personnelle 】 Programme d'études 】 albums de photos 】 babillard d'information 】

在VR全景中如何添加聚合热点?内容模块如何添加?

轻松学Pytorch-全卷积神经网络实现表情识别
![[C language] still don't understand the structure? Take a look at this article to give you a preliminary understanding of structure](/img/94/c9c7935aa0c98eb39a34377ad02b10.png)
[C language] still don't understand the structure? Take a look at this article to give you a preliminary understanding of structure

如何查询 SAPGUI 屏幕上某个字段对应的数据库表存储
![[6.4-6.10] wonderful review of Blog](/img/66/0cfc97bf4bc0c2b6e66c0419690ce5.png)
[6.4-6.10] wonderful review of Blog

Computer:成功教你如何使用一招—就能找回以前的密码(曾经保存的密码但当前显示为******号的密码)
![MySQL advanced Chapter 1 (installing MySQL under Linux) [i]](/img/f9/60998504e20561886b5f62eb642488.png)
MySQL advanced Chapter 1 (installing MySQL under Linux) [i]

Beijing Metro ticketing system
随机推荐
Micronet practice: image classification using micronet
This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue
Lingo12 software download and lingo language introduction resources
高考后选择哪所学校?VR全景校园全方位展示
轻松学Pytorch-全卷积神经网络实现表情识别
Design and reality of JSP project laboratory management system based on SSM doc
Code solution of simplex method (including super detailed code notes and the whole flow chart)
2022最强版应届生软件测试面试攻略,助你直通大厂
DDD landing practice repeat record of theoretical training & Event storm
全数字时代,企业IT如何完成转型?
frp reverse proxy
Debugging skills
2022.05.29 (lc_6079_price reduction)
【C语言】这些经典题型大家都掌握了吗?一文学会这些题
[6.4-6.10] wonderful review of Blog
MicroNet实战:使用MicroNet实现图像分类
618 great promotion is coming, mining bad reviews with AI and realizing emotional analysis of 100 million comments with zero code
Mongodb 唯一索引
Datascience & ml: detailed introduction to risk control indicators / field related concepts and dimension logic of risk control in the field of financial technology
[advanced C language] data storage [part I] [ten thousand words summary]