모든 하위 문서에 ObjectId가를 작성하지 :몽구스 자체 참조 스키마는 다음과 같이, 내가 자기 참조 필드가 몽구스의 스키마를
var mongoose = require('mongoose');
var CollectPointSchema = new mongoose.Schema({
name: {type: String},
collectPoints: [ this ]
});
CollectPoint 객체가 삽입 될 때 :
{
"name": "Level 1"
}
괜찮아, 결과는 같은 것으로 예상된다 :
{
"_id": "58b36c83b7134680367b2547",
"name": "Level 1",
"collectPoints": []
}
을하지만 자기 참조 서브 다큐를 삽입 할 때 아이 CollectPointSchema
의 _id
어디
{
"_id": "58b36c83b7134680367b2547",
"name": "Level 1",
"collectPoints": [{
"name": "Level 1.1"
}]
}
: ments는
{
"name": "Level 1",
"collectPoints": [{
"name": "Level 1.1"
}]
}
이것이 나에게 준다? 이건 _id
이 필요합니다. 임베디드 CollectPoint
항목을 선언 할 때
[이 재귀 함수] (https://gist.github.com/GSchutz/100358d4a614b563da29e72c5f8cd5e9)로이 문제를 해결합니다. – Guilherme