1
내 계획을 채우는 동안 결과를 가져올 수없는 이유 (mongoosejs 사용). 내 경우에는 내 범주, 하위 범주, 하위 범주 체계가 _id를 사용하지 않습니다. 맞춤 ID를 사용합니다.mongoosejs를 사용하여 채울 수 없습니다.
여기 내 제품 계획입니다 :
.....
categoryId: {
type: String,
ref: 'Catgory',
required: true
},
subcategoryId: {
type: String,
ref: 'Subcategory',
required: true
},
subsubcategoryId: {
type: String,
ref: 'Subsubcategory',
required: true
});
const Product = mongoose.model('Product', product);
module.exports = Product;
그리고 이것은 내 제품 컨트롤러 :
'getOne': function(req, res, next) {
if (typeof req.params.id !== 'string') return res.send({
'error-code': 3
});
Product.findOne({
_id: req.params.id
})
.populate({
path: 'category',
select: 'name'
})
.populate({
path: 'subcategory',
select: 'name'
})
.populate({
path: 'subsubcategory',
select: 'name'
})
.exec(function(error, response) {
if (error) return handleError(error);
return res.send(response);
})
}
는 당신의 도움을 주셔서 감사합니다.
오, 정말 고마워요. 다른 방법으로 다시 시도해 보겠습니다. –