Thief of Wealth

populate를 쓰면 ObjectId만 있던 field에 실제 값이 포함되어야 하는데,

 

.populate("something")  을 사용할 경우 오히려 something: [] 으로 표시되는 경우가 있다.

 

그리고 

TypeError: ID cannot represent value: <Buffer 5f 1e b7 da d2 1e 20 e3 4b 82 b4 8c>

 

식의 에러가 뜰것이다.

 

이때에는 mongoose schema를 잘못정해준 것이다.

 

예를 들면

 

questions이라는 property에 Question의 array를 참조하게 하고 싶다면 아래와 같이 선언하는게 아니라,

 

questions: {

    type: [Schema.Types.ObjectId],

    ref: 'Question'

}

 

이렇게 선언해야한다.

 

questions: [{

    type: Schema.Types.ObjectId,

    ref: 'Question'

}]

profile on loading

Loading...