_ID 반복 생성하고 난 다음 몽구스 스키마가 내 코드에서몽구스는
var mongoose = require('mongoose');
module.exports = mongoose.model('lf', {
_set : {type:Number},
a : {type:String},
b : {type:String},
c : {type:Number},
created_at : {type: Date, default: Date.now},
updated_at : {type: Date, default: Date.now}
},'flr');
내가 약간의 컬렉션을 조회하고 위의 스키마를 포함하는 스티치 JSON 객체를 생성합니다.
하지만 나는 점점 계속 몽구스에 저장() 작업을하고 때
Collection1.findOne({tfC: tfC}).lean().then(FP=> {
if (FP!== null && FP!== undefined){
new linkedFixed(FP).save(function(err, result){
console.log(err);
process.exit();
});
}
}).catch(error => {
console.error(error);
});
나는 점점 오전 오류 : 난 그렇게 내 스키마에이 _id를 정의하지
{ MongoError: E11000 duplicate key error collection: Da.flr index: _id_ dup key: { : ObjectId('5a0c8b3f10dfe503505fcaec') } at Function.MongoError.create
몽구스가이 색인에 중복 된 항목을 생성하는 이유는 무엇입니까?
find의 json 객체에 이미 _id가 있음을 알게되었습니다. 그러면 이것을 제거하면 오류가 발생합니다.
MongooseError: document must have an _id before saving
_id를 전달하지 않고 json 객체를 컬렉션에 저장할 수 있습니까? 몽구스가 무작위로 지정해야합니까?