• 技术文章 >数据库 >MongoDB

    mongodb复杂查询怎么办

     Ly Ly2020-06-09 14:01:15原创3326

    m内嵌文档复杂查询

    1、数据结构

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    {

        "_id":"1412243",

        "info":{

            "data":[

                {

                    "broker_id":0,

                    "receive_status":0,

                    "house_id":"1412243",

                    "gov_id":4127238,

                    "owner_phone":"",

                    "owner_name":"经纪人",

                    "source_name":"中原地产",

                    "source_logo":"http://file.zhugefang.com/5a351abc8fe131513429692_80_80.png",

                    "small_logo_url":"http://file.zhugefang.com/5a351abbbca1b1513429691_32_32.png",

                    "source":2,

                    "house_type":"1",

                    "pay_type":0,

                    "renzheng":"",

                    "header_pic":"",

                    "receive_time":0,

                    "city":7,

                    "service_phone":"4008985666,133188",

                    "house_source_desc":"房屋信息发布经纪人",

                    "source_url":"https://tj.centanet.com/ershoufang/tjnk0007892545.html",

                    "house_price":450,

                    "fee":"0.00",

                    "fee_new":"买方1% 卖方1%",

                    "feedback_total":"",

                    "feedback_content":[

                    ]

                },

                {

                    "broker_id":0,

                    "receive_status":0,

                    "house_id":"1412243",

                    "gov_id":2964975,

                    "owner_phone":"",

                    "owner_name":"经纪人",

                    "source_name":"链家地产",

                    "source_logo":"http://file.zhugefang.com/5a37669b7b3c21513580187_80_80.png",

                    "small_logo_url":"http://file.zhugefang.com/5a37669a87fc11513580186_32_32.png",

                    "source":1,

                    "house_type":"1",

                    "pay_type":0,

                    "renzheng":"",

                    "header_pic":"",

                    "receive_time":0,

                    "city":7,

                    "service_phone":"4008790056,7048",

                    "house_source_desc":"房屋信息发布经纪人",

                    "source_url":"http://tj.lianjia.com/ershoufang/101101622982.html",

                    "house_price":450,

                    "fee":"0.00",

                    "fee_new":"买方2.5%",

                    "feedback_total":"",

                    "feedback_content":[

                    ]

                }

            ],

            "company_ids":4

        },

        "city_name":"天津",

        "city":"tj",

        "cityid":"7",

        "craw_date":"2018-06-30"

    }

    2、db.books.find({"info.data":{"$elemMatch":{"owner_name":"经纪人","source_name":"中原地产"}}})

    这种数据结构 info 是一个对象,data中是一个列表,使用上面的命令就可以把数据筛选出来。

    如果info是一个列表,data也是一个列表

    db.books.find({info:{"$elemMatch":{data:{"$elemMatch":{house_id:"2185216"}}}}})

    使用上面的命令就能把数据筛选出来

    专题推荐:mongodb
    上一篇:mongodb查询不到数据 下一篇:mongodb复制集搭建步骤

    相关文章推荐

    • mongodb安装到哪个盘比较好?• mongodb安装目录在哪里?• mongodb安装取消后怎么重装?• mongodb查询不到数据

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网