MongoDB dup key:{:null}

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MongoDB dup key:{:null}相关的知识,希望对你有一定的参考价值。

我没有很多MongoDB经验,而且我遇到了以下有一个mLab实例:

E11000 duplicate key error index: development.users.$key_1 dup key: { : null } MongoError: E11000 duplicate key error index: development.users.$key_1 dup key: { : null }

我尝试按key字段排序,寻找null密钥,我不知道如何找到重复的null密钥。让这很困难的是,我甚至不确定要搜索谷歌或堆栈溢出来解决这个问题。任何帮助将不胜感激,以下是完整的错误:

Mongoose model 'index-single-done' event fired on 'Family' for index:
Object {key: 1}

With error:
    E11000 duplicate key error index: development.users.$key_1 dup key: { : null } MongoError: E11000 duplicate key error index: 
development.users.$key_1 dup key: { : null }
at Function.MongoError.create (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:497:72
at authenticateStragglers (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:477:5)
at Socket.<anonymous> (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/connection.js:333:22)
at Socket.emit (events.js:180:13)
at Socket.emit (domain.js:422:20)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onread (net.js:581:20)
Mongoose model 'index' event fired on 'Family' with error:
E11000 duplicate key error index: development.users.$key_1 dup key: { : null } MongoError: E11000 duplicate key error index: development.users.$key_1 dup key: { : null }
at Function.MongoError.create (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:497:72
at authenticateStragglers (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/pool.js:477:5)
at Socket.<anonymous> (/Users/myUserName/development/projectName/node_modules/mongodb-core/lib/connection/connection.js:333:22)
at Socket.emit (events.js:180:13)
at Socket.emit (domain.js:422:20)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onread (net.js:581:20)
答案

duplicate key error index: development.users.$key_1 dup key: { : null }

这意味着你的key字段被设置为仅接受唯一值,并且已经有一个key具有null值的记录,并且你不能插入另一个key作为null的文档。它类似于在SQL数据库中拥有主键。

检查你的mongoose架构,看起来你正在使用mongoose。

最有可能的:

  1. 保存记录时你没有传递密钥
  2. 如果您传递密钥,则其值为null
另一答案

我遇到了同样的问题

我尝试了不同的技术,无论是查看数据库验证还是数据库值,但没有发现任何无效

最后删除了收藏和问题解决了。虽然它不是一个好的解决方案,但在测试阶段它是可以的。

以上是关于MongoDB dup key:{:null}的主要内容,如果未能解决你的问题,请参考以下文章

Axon MongoDB - message='E11000 重复键错误集合 uniqueAggregateIndex dup key: : "101", : 0

MongoError:E11000 重复键错误集合:workflow.compnies 索引:username_1 dup key: username:null

在 MongoDB 中存储 null 与根本不存储密钥

IGNORE_DUP_KEY 的 DB2 等效项

mongodb删除某字段重复的操作

MongoError: E11000 duplicate key error collection: blog.users index: email_1 dup key