Javascript Mongo为具有唯一性的字段提供dup密钥错误:false

Javascript Mongo为具有唯一性的字段提供dup密钥错误:false,javascript,node.js,mongodb,mean-stack,Javascript,Node.js,Mongodb,Mean Stack,更新:感谢JohnnyHK的回答,我的问题已经解决了 初始问题:你知道我为什么会收到下面的错误消息吗?请注意,即使程序运行正常,“我们已连接”行之前的所有内容都会打印出来 DEBUG=cfcwebportal:* ./bin/www [Error: /home/ben/Code For Chicago/cfcwebportal/node_modules /mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bs

更新:感谢JohnnyHK的回答,我的问题已经解决了

初始问题:你知道我为什么会收到下面的错误消息吗?请注意,即使程序运行正常,“我们已连接”行之前的所有内容都会打印出来

DEBUG=cfcwebportal:* ./bin/www
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules
/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
We are connected
meBob
{ [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: cfc.students.$fname_1  dup key: { : "meBob" }]
  name: 'MongoError',
  message: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: cfc.students.$fname_1  dup key: { : "meBob" }',
  index: 0,
  code: 11000,
  errmsg: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: cfc.students.$fname_1  dup key: { : "meBob" }' }
We found students
这是我们正在尝试运行的文件。当每个字段都是唯一的时,它可以正常工作,但当任何字段都不是唯一的时,它不能正常工作,即使“unique”字段对于除“uname”之外的所有字段都设置为“false”

这是我当前的数据库:

> db.students.find()
{ "_id" : ObjectId("55637c8f00a648751180f0b1"), "uname" : "UBob", "password" : "AyBob", "fname" : "Bob", "lname" : "Robertson", "organization" : "CFC", "__v" : 0 }
{ "_id" : ObjectId("5563847fadcdb986135440e0"), "uname" : "death", "password" : "death", "fname" : "death", "lname" : "death", "organization" : "death", "__v" : 0 }
{ "_id" : ObjectId("556386ab95a85003141b4733"), "uname" : "Ben", "password" : "mypass", "fname" : "meBob", "lname" : "s", "organization" : "moredeath", "__v" : 0 }

Mongoose不会根据当前模式删除或重新定义以前创建的索引,因此我假设您以前在
fname
上有一个唯一的索引。手动将其放入shell中,然后重新启动应用程序:

db.students.dropIndex('fname_1')

哎呀,谢谢你给我指路:)你真是个该死的英雄,我的朋友。
db.students.dropIndex('fname_1')