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。
最有可能的:
- 保存记录时你没有传递密钥
- 如果您传递密钥,则其值为null
我遇到了同样的问题
我尝试了不同的技术,无论是查看数据库验证还是数据库值,但没有发现任何无效
最后删除了收藏和问题解决了。虽然它不是一个好的解决方案,但在测试阶段它是可以的。
以上是关于MongoDB dup key:{:null}的主要内容,如果未能解决你的问题,请参考以下文章
Axon MongoDB - message='E11000 重复键错误集合 uniqueAggregateIndex dup key: : "101", : 0
MongoError:E11000 重复键错误集合:workflow.compnies 索引:username_1 dup key: username:null
MongoError: E11000 duplicate key error collection: blog.users index: email_1 dup key