MongoDB正则查询操作
插入一条数据:{"_id" : ObjectId("61a83d5502bb260d1cec4e46"),"money" : 666,"id" : 1,"text1" : "ddfdfaf","text2" : "hkjhkjh"}{"_id" : ObjectId("61a8411402bb2614109443f2"),"money" : 888,"id" : 2,"text1" : "ddfa
·
插入一条数据:
{
"_id" : ObjectId("61a83d5502bb260d1cec4e46"),
"money" : 666,
"id" : 1,
"text1" : "ddfdfaf",
"text2" : "hkjhkjh"
}
{
"_id" : ObjectId("61a8411402bb2614109443f2"),
"money" : 888,
"id" : 2,
"text1" : "ddfaf2",
"text2" : "hkjhkjh2"
}
查询操作如下:
{text1:{"$regex":"f$"}} === {text1:/f$/} //以f结尾的
{text1:/^d.*f$/} //以d开头、f结尾的
{text1:/d(df){1}/} //查询包含d,紧跟着一个df字符串的名称
{money:{$ne:777}} //不等于777
{money:{$lt:777}} {money:{$lte:777}} //小于777 小于等于777
{money:{$gt:777}} {money:{$gte:777}} //大于777 大于等于777
{money:{$gt:555,$lt:888}} //大于555且小于888
查询正则表达式参考:mongodb正则$regex命令行简单使用 - 大坑水滴 - 博客园
更多推荐
所有评论(0)