【发布时间】:2020-05-05 02:19:12
【问题描述】:
我必须为每个单独的组件从 mongoDB 获取一条唯一记录。就我而言:对于组件 1,我想从数据库中获取第一个文档,对于组件 2,我想在 16 日之前获取第二个文档。
代码:
router.get('/:name', (res, req) => {
Buttons.findOne()
sort({name : 1})
.then(buttons => res.json(buttons))
});
以及函数代码:
async function getButtons() {
try {
const response = await axios.get('api/buttons/:name');
console.log(response);
catch (error) {
console.log(error)
}
}
【问题讨论】:
标签: arrays reactjs mongodb express axios