今天在单测的时候,出现这个问题。

我代码只定义了一个变量

let body = {name: 'wu'}

然后连续2次插入这个body数据

await exam.insertExam(body);

await exam.insertExam(body);

这样就生成了相同的_id.

mongdb可能会认为body是同一个数据,只生成了一个_id;

当又新建了一个变量body2,

就不会报错了。

mongodb E11000 duplicate key error collection: index: _id_ dup key的更多相关文章

  1. E11000 duplicate key error index: test.collection.$a.b_1 dup key: { : null } 报错记录

    这个一般分为两种情况,第一新增数据出现约束.而你在orm里面写了唯一约束.这种情况就比较简单,添加数据时保证数据字段唯一性就好了. 第二种情况比较难找,因为你发现你在orm里面并没有写约束,但是还是插 ...

  2. E11000 duplicate key error index

    E11000 duplicate key error index mongodb插入报错,重复主键问题,有唯一键值重复 一般使用collection.insertOne(doc);插入一条已存在主键的 ...

  3. Oracle deadlock SX/SSX caused by no index on foreign key.

    Example to show the dead lock caused by lack of index on foreign key of child table. Session 1: crea ...

  4. 【异常】update更新java.sql.SQLException: Duplicate entry '2019-07-30 00:00:00-110100' for key

    1 详细异常信息 User class threw exception: java.sql.SQLException: Duplicate entry '2019-07-30 00:00:00-110 ...

  5. Fix the “No Private Key” Error Message

    This article will show you how to correct the “No Private Key” error message in Windows Internet Inf ...

  6. java.util.regex.PatternSyntaxException: Unexpected internal error near index 1 \ ^

    1 String a = "1991\12\16"; 2 String[] split = a.split("\\"); 3 System.out.printl ...

  7. Error Code: 1068. Multiple primary key defined

    1.错误描述 10:10:38 alter table user add num int(8) primary key first Error Code: 1068. Multiple primary ...

  8. [转] Linux有问必答:如何修复“sshd error: could not load host key”

    编译自:http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html作者: GOLinux 本文地址:https://linux.cn/ ...

  9. 【err】VIDEOIO ERROR: V4L: index 0 is not correct!Unable to connect to camera

    前言 新到手一块板子,程序编译成功之后,运行出现错误,不能连接到摄像头. 问题 VIDEOIO ERROR: V4L: index is not correct! Unable to connect ...

随机推荐

  1. Ubuntu 安装 Courier New字体和雅黑consolas字体

    一直觉得Ubuntu下的字体不是很好,但毕竟不影响使用,然后作开发的时候eclipse的字体完全没有windows下的两大适合编成的字体courier new 和consloas .可以使用系统安装字 ...

  2. ASP.NET--Attribute定义及用法

    1.Attribute定义 公共语言运行时允许添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法和属性等.Attributes和Microsoft .N ...

  3. YAML说明

    YAML说明 https://www.cnblogs.com/songchaoke/p/3376323.html XML的简化

  4. [React] Understanding setState in componentDidMount to Measure Elements Without Transient UI State

    In this lesson we'll explore using setState to synchronously update in componentDidMount. This allow ...

  5. 在MAC下怎样用SSH连接远程LINUXserver

    首页,打开MAC的命令终端,检查是不是用root用的登录的,假设不是的话请输入命令:sudo -i切换到root. 然后,输入:ssh ip地址,假设主机存在的话会提示你输入password,输入正确 ...

  6. POJ 3664 Election Time 题解

    这道题网上非常多人都会说easy,水题之类的话,只是我看了下说这种话的人的程序,能够说他们的程序都不及格! 为什么呢?由于他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这种程序).那样自然 ...

  7. C++_关于const 的全面总结

    C++中的constkeyword的使用方法很灵活.而使用const将大大改善程序的健壮性.本人依据各方面查到的资料进行总结例如以下,期望对朋友们有所帮助. Const 是C++中经常使用的类型修饰符 ...

  8. LeetCode -- 求字符串数组中的最长公共前缀

    题目描写叙述: Write a function to find the longest common prefix string amongst an array of strings.就是给定1个 ...

  9. iOS学习必须了解的七大手势

    文章只要你有一点点基础应该就可以看的懂,文章只为学习交流 #import "ViewController.h" @interface ViewController () @prop ...

  10. JAXB xml与javaBean的转换

    转自:https://blog.csdn.net/lydong_/article/details/79812626 `1. 1.不认识到犯错,然后得到永久的教训. 也不是所谓的教训吧,真正的教训来自于 ...