【发布时间】:2020-10-28 05:34:47
【问题描述】:
我有一个 GET 请求,当我输入餐厅时成功返回餐厅。它使用排序规则和索引,因此可以找到大小写,没问题。
问题是我必须输入准确的餐厅名称,否则 Postman 中的 GET 请求会失败。
例如要查找名为Riverside Shard Inn 的餐厅,只有在查询中输入Riverside Shard Inn 时,我的GET 请求才会找到它。如果我输入 Riverside Shard 或 Shard Inn 这将失败。
所以我想我需要在后端进行部分字符串匹配。不知道该怎么做。
这是我的 GET 请求代码:
// Route to return a single restaurant using a collection that has collation//
app.route("/restaurants/:restaurantName")
.get(function(req, res){
Restaurant.find({BusinessName: req.params.restaurantName}, function(err, foundRestaurant){
if (foundRestaurant) {
res.send(foundRestaurant)
} else {
res.send("No restaurants matching that title was found.");
}
});
});
【问题讨论】:
标签: node.js express mongoose get mongodb-query