本文介绍了Express.js - 过滤URL中的mongodb id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题的灵感来源于但是在我的情况下,我需要过滤MongoId。
This question inspired by this post but in my case I need to filter MongoId. Is it possible to make filtering easily that the below because I need use it in each route?
app.post('/:mongoId(^[0-9a-fA-F]{24}$)', function(req, res){
// Send query based on mongoId
}
推荐答案
你几乎在那里,只是不要添加 ^
和 $
锚点,而大写的 AF
范围甚至不需要,因为Express似乎匹配不区分大小写:
You're almost there, just don't add the ^
and $
anchors. And the uppercase A-F
range isn't even necessary since Express seems to match case-insensitive:
app.post('/:mongoId([0-9a-f]{24})', function(req, res){
var id = req.param('mongoId');
...
});
这篇关于Express.js - 过滤URL中的mongodb id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!