에 데이터를 저장하려고 할 때 내가 스키마가 (내가 저장하여 데이터를 저장하려고 할 때나는 중복 키 에러 인덱스를 얻고있다 : 나는 MongoDB를
var RegisterInfoSchema= new Schema({
Organization:String,
NGOName:String,
Acronym:String,
Address:String,
Province:String,
District:String,
Tehsil:String,
Telephone_number:String,
Website:String,
Demographics:String,
Username:{type:String ,index: {unique:true}},
Password:String
})
exports.savePersonalInfo = function (req,res){
console.log("savePersInfo CALLED");
var receivedObj = new RegisterInfo({
Organization: req.body.regOrgType ,
NGOName: req.body.regName,
Acronym: req.body.regAcronym ,
Address: req.body.regAddress ,
Province: req.body.regProvince,
District: req.body.regDistrict,
Tehsil: req.body.regTehsil ,
Telephone_number: req.body.regTelNo ,
Website: req.body.regWebAddr,
Demographics: req.body.regDemographics,
Username: req.body.regUserName ,
Password: req.body.regPsw
});
receivedObj.save(function(err){
console.log("inside Save ");
if(err){
console.log(err);
}
else{
console.log("Saved!!");
res.send("");
}
});
}
는 사용자 이름 에이 색인됩니다)
{[MongoError : E11000 키 에러 인덱스 복제 :. testdb.registerinfos을 $ 님 DUP 키 : {: 널 (null)}] 이름 : 'MongoError', 오류 : 'E11000 중복 메소드는 다음과 같은 오류를 제공 키 오류 인덱스 : testdb.registerinfos. $ username_1 dup 키 : {: null} ', 코드 : 11000, N : 0, lastOp : 0, connectionId : 339527, 확인 : 1}
그것은 그 _id가 설정이고 그래서 내가 나 자신을 ID를 지정해야 새 행 – Sammaye
이라고 생각 될 수 있을까요? @Sammaye – ana
당신은 _id를 지정할 필요가 없습니다.이 오류가 발생했을 때 어떤 코드를 사용하고 있습니까? 새로운 행을 만들려고 할 때가 아니라고 확신합니까? 이후 새로운 행을 만들려고 할 때이 일이 발생한다면 그것은 ofc 색인의 becuae입니다. – Sammaye