유형, 단위, 항목이 포함 된 ItemCatalog 컬렉션이 있습니다.동일한 컬렉션에서 참조를 채우는 몽구스
{
"_id": ObjectId("57b188d67aa27ae4ee87e11c"),
"type": [
{
"_id" : ObjectId("57b188d6e128064381ae2f2f"),
"typeName" : "abc"
}
],
"__v": 0,
"unit": [
{
"_id" : ObjectId("57b188e4e128064381ae2f54"),
"unit" : "mg"
}
],
"items": [
{
"itemStrength" : "100",
"itemName" : "a1",
"idType" : ObjectId("57b188d6e128064381ae2f2f"),
"idUnit" : ObjectId("57b188e4e128064381ae2f54"),
"isActive" : true,
"_id" : ObjectId("57b188f3e128064381ae2f7a")
}
]
}
가 어떻게 활성 및 항목 데이터를 검색 할 수 아래처럼 보이는 수집의
var Categories = new Schema({
typeName: String
});
var MeasurementUnit = new Schema({
unit: String
});
var Items = new Schema({
itemName: String,
itemStrength: String,
idType: { type: Schema.Types.ObjectId, ref: 'Categories' },
idUnit: { type: Schema.Types.ObjectId, ref: 'MeasurementUnit' },
isActive: Boolean
});
var ItemCatalog = new Schema({
type: Categories,
unit: MeasurementUnit,
items: Items
});
문서 idType 및 idUnit을 채우는 대신 전체 문서를 가져 와서 클라이언트에서 반복?
는 가장 좋은 방법은 같은 구현이
{
_id: "57b188d67aa27ae4ee87e11c",
drugs: [
{
itemStrength: "100",
itemName: "a1",
typeName: "abc",
unit: "mg",
isActive: true,
_id: "57b188f3e128064381ae2f7a"
}
]
}
같은 데이터 뭔가를 제안하십시오 할 수 있습니다.
'type'과 'unit'이 별도의 컬렉션이 아닌 [sub documents] (http://mongoosejs.com/docs/subdocs.html)에 저장되어 있기 때문에 인구를 사용하는 것이 불가능하다고 생각합니다. – robertklep
고마워요 @robertklep – vijay