2016-09-12 2 views
0

새로운 문서 참조 배열을 설정할 때마다 계속 오류가 발생합니다. 이로 인해 다음과 같은 오류가 발생합니다. "$ isMongooseDocumentArray '의 속성을 읽을 수 없습니다.";. 다른 스키마의 다른 문서에 대한 참조 배열을 사용하여 문서를 업데이트하는 방법은 무엇입니까? 그 문서 참조 배열을 새 집합으로 대체하려고합니다. 문제 발견몽구스 : 문서 업데이트시 새로운 문서 참조 배열 설정

Lets say I had this schema with a particular reference: 

const userCommandSchema = mongo.Schema({ 
    objectID: mongo.Schema.ObjectId, 
    userID: { type: String, required: true }, 
    command: { type: String, required: true }, 
    summary: { type: String }, 
    isFavourite: { type: Boolean, default: false }, 
}, 
{ timestamps: true } 
); 

const UserCommandSequenceSchema = mongo.Schema({ 
    objectID: mongo.Schema.ObjectId, 
    userID: { type: String, required: true }, 
    commandSequenceTitle: { type: String, required: true }, 
    commandSequenceDescription: { type: String, required: false }, 
    commands: [{ type: mongo.Schema.Types.ObjectId, ref: 'UserCommand' }], 
}, 
{ timestamps: true } 
); 


// How would I go about updating an array of document references? 

const arrayOfObjectIDs = [mongo.Types.ObjectId("57d2e31f0098c69c4eefde53"), mongo.Types.ObjectId("57d2e31f0098c69c4eefde57")]; 

const query = { _id: id }; 

const update = { $set: { 
    commandSequenceTitle, 
    commandSequenceDescription, 
    commands 
}, 
}; 

const options = { new: true }; 

UserCommandModel.findOneAndUpdate(query, update, options) 
.exec() 
.then(({ _id, commandSequenceTitle, commandSequenceDescription, commands, createdAt, updatedAt }) => { 
}) 
.catch((err) => { 
    console.log(err); 
}); 

답변

0

, 내가 잘못된 스키마 모델 -_-

를 호출 한 것