node.js - 如何在 MongoDB 中按 _id 过滤项目?
问题描述
该功能不起作用:
router.get('/getCompetitions', (request, response) => {
competitionTemplateCopy.find({"_id": 1})
.then(data => response.json(data))
.catch(error => response.json(error))
});
解决方案
试试这个 :
competitionTemplateCopy.find(_id:1)
.then(data => response.json(data))
.catch(error => response.json(error))
});
你应该添加 _id: { type: Number, },
你的模型
推荐阅读
- python - 我如何在 django 中运行脚本?
- javascript - 两个可编辑的列在 DT 中相互计算
- python - 使用 Pandas 数据框匹配关键字(字符串)
- java - 如何将 Rest-Assured Request 和 Response 控制台日志写入 Cucumber 报告
- python - 大熊猫从日期时间索引长到宽
- android - 如何为 facebook 应用程序创建有效的隐私政策 URL ..?
- reactjs - 在发送下一个请求之前等待上一个 axios 响应完成
- apexcharts - Apexcharts 热图中的奇怪颜色
- javascript - Puppeteer:将截获的图像请求的 URL 更改为 base64 图像
- image-processing - NetVips:使用 1 个波段创建复合并应用 icc 配置文件