首页 > 解决方案 > 如何在 MongoDB 中按 _id 过滤项目?

问题描述

我自己制作了_ids: 在此处输入图像描述

该功能不起作用:

router.get('/getCompetitions', (request, response) => {
    competitionTemplateCopy.find({"_id": 1})
    .then(data => response.json(data))
    .catch(error => response.json(error))
});

标签: node.jsreactjsmongodb

解决方案


试试这个 :

    competitionTemplateCopy.find(_id:1)
    .then(data => response.json(data))
    .catch(error => response.json(error))
});

你应该添加 _id: { type: Number, },你的模型


推荐阅读