몽구스 색인 생성에 문제가 있습니다. 고유 한 employeeId 필드가 있습니다. 직원 문서를 만들면 "employeeId_1"색인이 생성되고 색인 "id"이 있습니다. 나는 그것이 "_id"이어야한다고 생각한다. 누군가 내가 뭘 잘못하고 있는지 걸을 수 있습니까? 다음은 코드입니다.몽구스 색인 생성
var mongoose = require('mongoose');
var ObjectId = mongoose.SchemaTypes.ObjectId;
var eContactSchema = mongoose.Schema({
contacttype:{type: Number},
name:{type: String, required:true},
phone:{type: String, trim: true},
mail1:{type: String, trim: true},
mail2:{type: String, trim: true},
city:{type: String, trim: true},
state:{type: String, trim: true},
zip:{type: String, trim: true}
})
var eCourseSchema = mongoose.Schema({
course:{type: ObjectId, required:true, unique: true},
title:{type: String},
notes:{type: String, trim:true},
expire:{type: Date},
deleted: {type: Boolean, default: false}
})
var eAppSchema = mongoose.Schema({
appName:{type: String, required: true, trim: true},
view:{type: Boolean, default: false},
create:{type: Boolean,default: false},
edit:{type: Boolean,default: false},
del:{type: Boolean,default: false}
})
var employeesSchema = mongoose.Schema({
firstName:{type: String, trim:true, required:true},
lastName:{type: String, trim:true, required:true},
employeeId: {type: String, trim:true, required:true, unique: true},
active: {type: Boolean, default: true},
admin: {type: Boolean, default: false},
title: {type: String, trim:true},
pin:{type:String, trim: true},
contacts:[eContactSchema],
courses:[eCourseSchema],
apps:[eAppSchema]
})
module.exports = db.model('employees', employeesSchema,'employees');
다음은 문서 작성 방법입니다.
exports.addEmployee = function (data, callback) {
employees.create(data, function (err) { callback(err) });
};
다음은 getIndex 결과입니다. 어떤 이유로 나는이 문제를 재현 할 수 없지만 이것과 함께 employeeId_1이라는 이름의 또 다른 색인이있을 것입니다. employeeId_1 키에 중복 오류가 발생합니다.
[
{
"v": 1,
"key": {
"_id":1
},
"ns": "Management.employees",
"name": "_id_"
}
]
합니다. 쉘에서'db.employees.getIndexes()'출력을 포함하도록 질문을 편집 할 수 있습니까? – JohnnyHK