【发布时间】:2018-10-09 06:37:23
【问题描述】:
我的控制台出现了这个错误:
{ MongoError: E11000 重复键错误集合:mean.companies 索引:students_1 复制键:{:未定义} 在 C:\mean\node_modules\mongodb-core\lib\connection\pool.js:595:61 在 authenticateStragglers (C:\mean\node_modules\mongodb-core\lib\connection\pool.js:513:16) 在 Connection.messageHandler (C:\mean\node_modules\mongodb-core\lib\connection\pool.js:549:5) 在 emitMessageHandler (C:\mean\node_modules\mongodb-core\lib\connection\connection.js:309:10) 在套接字。 (C:\mean\node_modules\mongodb-core\lib\connection\connection.js:452:17) 在 Socket.emit (events.js:180:13) 在 addChunk (_stream_readable.js:269:12) 在 readableAddChunk (_stream_readable.js:256:11) 在 Socket.Readable.push (_stream_readable.js:213:10) 在 TCP.onread (net.js:581:20) 名称:'MongoError',消息:'E11000 重复键错误集合:mean.companies 索引: student_1 dup 键:{:未定义}',确定:0,errmsg:'E11000 重复键错误集合:mean.companies 索引:students_1 dup 键:{:未定义}',代码:11000,代号:'DuplicateKey'}
我有 2 个模式用户和公司,我想用一个键相互连接: 这是我的Uschema
const UserSchema = mongoose.Schema({
nama:{
type : String
},
email:{
type : String,
require : true,
unique : true
},
nim:{
type : String,
require : true,
unique : true
},
jurusan:{
type : String
},
prodi:{
type : String
},
angkatan:{
type : String
},
password:{
type : String,
require : true
},
company:{
type : String,
ref : 'company',
unique : false
}
});
这是 CompanySchema:
const CompanySchema = mongoose.Schema({
perusahaan:{
type : String,
require : true
},
deskripsi:{
type : String,
require : true
},
alamat:{
type : String,
require : true
},
email_perusahaan:{
type : String,
require : true
},
telepon:{
type : String,
require : true
},
website:{
type : String,
require : true
},
status:{
type : String,
require : false
},
students:[{
type: String,
ref: 'user',
unique : false
}]
});
【问题讨论】:
标签: node.js mongodb express mongoose