设为首页 加入收藏

TOP

MongoDB的模糊查询操作(类关系型数据库的 like 和 not like)(一)
2019-09-17 16:32:30 】 浏览:45
Tags:MongoDB 模糊 查询 操作 关系型 数据库 like not

1.作用与语法描述

作用: 正则表达式是使用指定字符串来描述、匹配一系列符合某个句法规则的字符串。许多程序设计语言都支持利用正则表达式进行字符串操作。MongoDB 使用 $regex 操作符来设置匹配字符串的正则表达式。

语法一

{ <field>: { $regex: /pattern/, $options: '<options>' } }
{ <field>: { $regex: 'pattern', $options: '<options>' } }
{ <field>: { $regex: /pattern/<options> } }

语法二

{ <field>: /pattern/<options> }

 

2.案例演示

假设MongoDB中存放了我们OrderService服务的消息信息,其数据如下:

(以下为演示所用到的9个文档)

{
    "_id" : ObjectId("5d305b1c4857fc49c0c14c81"),
    "order" : "QQ00001",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305b3b4857fc49c0c14c82"),
    "order" : "QQ00001",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305b404857fc49c0c14c83"),
    "order" : "QQ00002",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305b454857fc49c0c14c84"),
    "order" : "QQ00002",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305b4b4857fc49c0c14c85"),
    "order" : "QQ00003",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305b4f4857fc49c0c14c86"),
    "order" : "QQ00003",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>ERR</Head><ERROR>重复下单</ERROR></Response>\""
},

{
    "_id" : ObjectId("5d305bb74857fc49c0c14c87"),
    "order" : "QQ00003",
    "data" : "\"<?xml version='1.0' encoding='UTF-8'?><Response service=\\\"OrderService\\\"><Head>OK</Head><Body><OrderResponse filter_mmm=\\\"2\\\" destcity=\\\"shenzheng\\\" origincode=\\\"QQ0003\\\" /></Body></Response>\""
},

{
    "_id" : ObjectId("5d305bd14857fc49c0c14c88"),
    "order" : "QQ00002",
    "data" : "\"
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇windows scala helloworld例子详解 下一篇【MySQL】mysql中的锁机制

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目