在JS上运行正则表达式的Mongo Query在Node JS中运行 [英] Mongo Query with Regex in Node JS operating ON A VARIABLE

查看:72
本文介绍了在JS上运行正则表达式的Mongo Query在Node JS中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有问题.我想使用像LIKE这样的常规关系数据库查询Node JS文件中的MongoDB.问题是我想喜欢的东西不是字面意思……它是一个变量!到目前为止,我还没有找到执行此操作的好方法.这是我拍摄的"durrr第一次尝试"镜头:

I have a problem here. I want to query my MongoDB in my Node JS file using something like LIKE for a conventional relational db. The problem is the thing I want to LIKE to is not a literal...it is a variable! I have found no good way to do this as of yet. Here was the "durrr first try" shot I took at it:

var result = postData.replace(/\+/g,' ').substring(5);
db.testlogwiki.find({"line_text" : /result/ };
//predictably only matches to the literal "result" as opposed to my variable

testlogwiki是在Mongo中制作的...我正在运行它,并且确实可以对带有包含结果"的"line_text"的数据库条目进行处理.

testlogwiki is made in Mongo...I have it running and this does mach to db entries with "line_text" containing "result" literally.

这似乎是一个非常简单的问题...

It seems like a very simple question...

推荐答案

尝试以下方法:

db.testlogwiki.find({"line_text" : new RegExp(result) };

这篇关于在JS上运行正则表达式的Mongo Query在Node JS中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆