账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    E11000 duplicate key error collection
    92
    0
    const CommentsSchema = new Schema({
      userId: { type: Schema.Types.ObjectId, ref: 'User', require: true },
      articleId: { type: Schema.Types.ObjectId, ref: 'Article', require: true },
      content: { type: String, require: true },
      created_at: { type: Date, default: Date.now },
      thumbsUp: [{ type: Schema.Types.ObjectId, ref: 'User' }],
      thumbsDown: [{ type: Schema.Types.ObjectId, ref: 'User' }]
    })
    commentModel = {
      userId: ctx.session.user._id || ctx.request.body.userId,
      articleId: articleId,
      content: content
    };
    
    Comments.create(commentModel)

    第二次插入数据的时候报错

      name: 'MongoError',
      message: 'E11000 duplicate key error collection: myblog.comments index: thumbsUp_1 dup key: { : undefined }',
      driver: true,
      code: 11000,
      index: 0,
      errmsg: 'E11000 duplicate key error collection: myblog.comments index: thumbsUp_1 dup key: { : undefined }',
      getOperation: [Function],
      toJSON: [Function],
      toString: [Function] }

    请问该如何解决

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • The "E11000 duplicate key error collection" error occurs when a database table has duplicate keys, and the database server is unable to insert or update a record with the same key. This error is usually caused by a database transaction that tries to insert a record with a duplicate key, but the server is unable to handle the transaction because it has a duplicate key. To resolve this error, you should check the database schema to make sure that there are no duplicate keys in the table. You should also check the database transaction log to see if the transaction was able to proceed to the next step, or if it was rolled back because of the duplicate key error. If the error persists, you may need to consult with a database administrator or a database expert to determine the cause of the error and find a solution.

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部