在nodejs

时间:2018-05-19 11:12:02

标签: node.js mongodb

我正在尝试根据其ID获取子文档,但我得到的支持投影选项不受支持。

router.get('/:category/:item', async (req, res) => {
    try {
        const item = await Category.findOne(
            { category_id: req.params.category },
            { items: { $elementMatch: { item_id: req.params.item } } });

        res.status(200).send(item);    
})

// Schema

const categorySchema = new Schema({
    category_id,
    name,
    items: [
       item_id,
       item_name
    ]
})

我希望我已经澄清了这个问题,如果仍然存在困惑,你可以要求许可。

0 个答案:

没有答案