【发布时间】:2016-10-13 02:06:30
【问题描述】:
我在使用 Mongoose 进行 $regex 查询时遇到问题;
以下工作正常:
Media.count(
{ "filename" :
{ $regex: /placeholder(-)?(\w+.)?.(\w+)?$/gm } },
function(err, res){
...
以下不起作用:
var xp = new RegExp("placeholder(-)?(\w+.)?.(\w+)?$", "gm")
Media.count(
{ "filename" :
{ $regex: xp } },
function(err, res){
...
我也尝试了以下也不起作用:
var xp = new RegExp("placeholder(-)?(\w+.)?.(\w+)?$")
Media.count(
{ "filename" :
{ $regex: xp, $options: 'gm' } },
function(err, res){
...
出于某种原因,我觉得 Mongoose 不接受 RegExp 对象?我遇到的问题是我需要用变量替换“占位符”,因此我需要使用 RegExp 来完成这项工作......
以前有人遇到过这个问题
【问题讨论】:
标签: javascript regex node.js mongodb mongoose