【发布时间】:2019-04-17 15:44:24
【问题描述】:
以下是我按城市查询搜索的代码。在我的帖子中找不到我> 我需要能够搜索特定城市并获取与该城市匹配的字段的所有记录。例如,如果 city 是 Downtown,我想要所有包含 city Downtown 的记录
router.get("/search", (req, res, next) =>{
const city = req.query.city;
Facility.findAll(city)
.select('name type mobile price streetName city state _id')
.exec()
.then(docs => {
console.log("From database", docs);
if (docs) {
res.status(200).json({
facility: docs
});
} else {
res
.status(404)
.json({ message: "No valid entry found for provided City" });
}
})
.catch(err => {
console.log(err);
res.status(500).json({ error: err });
});
});
【问题讨论】:
-
您是否需要将_id 添加到选择提要中?只是好奇???
-
请说明您遇到的错误
-
消息:“模型“设施”的路径“_id”处的值“搜索”转换为 ObjectId 失败,
标签: node.js mongodb api express