无法使用mongoosejs进行填充

为什么我不能得到结果,而试图填充我的计划(我使用mongoosejs)。 在我的情况下,我的类别,子类别,sububcategoryscheme不使用_id。 我使用自定义ID。

这是我的产品scheme:

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

非常感谢您的帮助。

不幸的是,截至目前,您只能使用外部_idpopulate字段。 在不同的领域填充已经在mongooseGitHub相当长的一个重要要求的function 。