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); 
     }) 
} 

はあなたの助けのためにありがとうございました。

答えて

1

残念ながら、現時点ではpopulateフィールドは外国_id秒しか使用できません。さまざまなフィールドに入力すると、かなりの間、heavily requested feature on the mongoose GitHubになりました。

+0

ああ、ありがとうございます。別の方法でもう一度試してみます。 –

関連する問題