zoukankan      html  css  js  c++  java
  • pymongo的正则查询

    一:数据样式

    /* 1 */
    {
        "_id" : ObjectId("5ea4fde22a89d7c2fc456ad4"),
        "name" : "陕西西安",
        "location" : "新城区"
    }
    
    /* 2 */
    {
        "_id" : ObjectId("5ea4fe152a89d7c2fc456b19"),
        "name" : "内蒙古鄂尔多斯",
        "location" : "乌兰镇"
    }
    
    /* 3 */
    {
        "_id" : ObjectId("5ea4fe292a89d7c2fc456b3b"),
        "name" : "内蒙古巴彦淖尔",
        "location" : "彩虹镇"
    }
    
    /* 4 */
    {
        "_id" : ObjectId("5ea4fe6c2a89d7c2fc456b9c"),
        "name" : "广西桂林市",
        "location" : "七星区"
    }

     需求:查询名字包含内蒙古的所有数据

        def find_by_regex(self):
            if self.connect_result:
                result = self.db["test1"].find({"name":{"$regex":""}})
                for i in result:
                    print(i)
    
    # 结果
    {'_id': ObjectId('5ea4fe152a89d7c2fc456b19'), 'name': '内蒙古鄂尔多斯', 'location': '乌兰镇'}
    {'_id': ObjectId('5ea4fe292a89d7c2fc456b3b'), 'name': '内蒙古巴彦淖尔', 'location': '彩虹镇'}

    # TODO

  • 相关阅读:
    解决IE8下VS2005,VS2008一些向导提示脚本错误问题
    12-7
    12.4
    写在十一月的尾巴
    11.28
    htm&css 颜色的浮动
    11.27
    11.26
    html基础——表格练习
    html基础——div/span
  • 原文地址:https://www.cnblogs.com/meloncodezhang/p/12778441.html
Copyright © 2011-2022 走看看