E11000 duplicate key error index

简介: E11000 duplicate key error indexmongodb插入报错,重复主键问题,有唯一键值重复一般使用collection.insertOne(doc);插入一条已存在主键的记录会报错使用MDAO的public Key save(T entity){ return this.ds.save(entity);}一般不会报错,save方法必须是一个完整的实体,而不能保存一个字段实体。

E11000 duplicate key error index

mongodb插入报错,重复主键问题,有唯一键值重复

一般使用collection.insertOne(doc);插入一条已存在主键的记录会报错

使用MDAO的

public Key<T> save(T entity)
{
    return this.ds.save(entity);
}

一般不会报错,save方法必须是一个完整的实体,而不能保存一个字段实体。如下所示:可以对User的实体进行报错,不能对Test的User属性进行保存

public class User {

}
public class Test{
  private User user;
  public void setUser(User user){
       this.user = user;  
    }  
   public User getUser(){
       return user;
  } 
}

 

遗失的拂晓
目录
相关文章
|
9月前
|
数据库 Python
Duplicate entry for key username
Duplicate entry for key username
101 0
|
数据库
MongoError: E11000 duplicate key error collection: blog.users index: email_1 dup key
MongoError: E11000 duplicate key error collection: blog.users index: email_1 dup key
|
JavaScript
[Vue warn]: Duplicate keys detected: ‘1‘. This may cause an update error. for循环,key重复报错
[Vue warn]: Duplicate keys detected: ‘1‘. This may cause an update error. for循环,key重复报错
88 0
|
关系型数据库 MySQL 数据库
解决出现的SQLIntegrityConstraintViolationExceptionw:Duplicate entry ‘10‘ for for key ‘user.PRIMARY‘问题
解决出现的SQLIntegrityConstraintViolationExceptionw:Duplicate entry ‘10‘ for for key ‘user.PRIMARY‘问题
312 0
|
SQL 数据库
ON DUPLICATE KEY UPDATE
ON DUPLICATE KEY UPDATE
151 0
ON DUPLICATE KEY UPDATE
|
索引
LeetCode 287. Find the Duplicate Number
给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个重复的整数。假设只有一个重复的整数,找出这个重复的数。
95 0
LeetCode 287. Find the Duplicate Number
|
SQL 关系型数据库 数据库
Duplicate entry '0' for key 'PRIMARY'的一种可能的解决办法
在MySQL设计好数据库往往数据库中插入数据的时候, 因为主键ID默认是不赋值的,只给其他项目赋值了,相关的SQL代码是这样的   StringBuilder strSql = new StringBuilder(); strSql.
2756 0