国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python操作mongodb數(shù)據(jù)庫進(jìn)行模糊查詢操作示例

Python操作mongodb數(shù)據(jù)庫進(jìn)行模糊查詢操作示例

2021-03-03 00:04shaomine Python

這篇文章主要介紹了Python操作mongodb數(shù)據(jù)庫進(jìn)行模糊查詢操作,結(jié)合實(shí)例形式分析了Python連接MongoDB數(shù)據(jù)庫及使用正則表達(dá)式進(jìn)行模糊查詢的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python操作mongodb數(shù)據(jù)庫進(jìn)行模糊查詢操作。分享給大家供大家參考,具體如下:

?
1
2
3
4
5
6
7
8
9
10
# -*- coding: utf-8 -*-
import pymongo
import re
from pymongo import MongoClient
#創(chuàng)建連接
#10.20.66.106
client = MongoClient('10.20.4.79', 27017)
#client = MongoClient('10.20.66.106', 27017)
db_name = 'ta'
db = client[db_name]

假設(shè)mongodb數(shù)據(jù)庫中school 集合中有一些數(shù)據(jù)記錄

?
1
2
3
4
5
6
7
8
9
10
11
{ "_id" : 1, "zipcode" : "63109", "students" : { "comments" : "python abc" } }
{ "_id" : 2, "zipcode" : "63110", "students" : { "comments" : "python abc" } }
{ "_id" : 3, "zipcode" : "63109", "students" : { "comments" : "python abc" } }
{ "_id" : 4, "zipcode" : "63109", "students" : { "comments" : "python abc" } }
{ "_id" : 5, "zipcode" : "63109", "students" : { "comments" : "python abc" } }
{ "_id" : 7, "zipcode" : "63109", "students" : { "comments" : "python abc" }, "school" : "102 python abc" }
{ "_id" : 8, "zipcode" : "63109", "students" : { "comments" : "python abc" }, "school" : "100 python abc xyz" }
{ "_id" : 9, "zipcode" : "100", "students" : { "name" : "mike", "age" : 12, "comments" : "python" } }
{ "_id" : 10, "zipcode" : "100", "students" : { "name" : "Marry", "age" : 42, "comments" : "this is a python" } }
{ "_id" : 11, "zipcode" : "100", "students" : { "name" : "joe", "age" : 92, "comments" : "this is a python program" } }
{ "_id" : 12, "zipcode" : "100", "students" : { "name" : "joedd", "age" : 34, "comments" : "python is a script language" } }

現(xiàn)在要對students中comments的數(shù)據(jù)進(jìn)行模糊查詢, python中模糊查詢要借助正則表達(dá)式:

1、查詢comments中包含"abc"的記錄:

?
1
2
for u in db.school.find({'students.comments':re.compile('abc')}):
  print u

結(jié)果如下:

{u'students': {u'comments': u'python abc'}, u'_id': 1.0, u'zipcode': u'63109'}
{u'students': {u'comments': u'python abc'}, u'_id': 2.0, u'zipcode': u'63110'}
{u'students': {u'comments': u'python abc'}, u'_id': 3.0, u'zipcode': u'63109'}
{u'students': {u'comments': u'python abc'}, u'_id': 4.0, u'zipcode': u'63109'}
{u'students': {u'comments': u'python abc'}, u'_id': 5.0, u'zipcode': u'63109'}
{u'students': {u'comments': u'python abc'}, u'school': u'102 python abc', u'_id': 7.0, u'zipcode': u'63109'}
{u'students': {u'comments': u'python abc'}, u'school': u'100 python abc xyz', u'_id': 8.0, u'zipcode': u'63109'}

2、查詢comments中包含"this is"的記錄:

?
1
2
for u in db.school.find({'students.comments':re.compile('this is')}):
  print u

結(jié)果如下:

{u'students': {u'age': 42.0, u'name': u'Marry', u'comments': u'this is a python'}, u'_id': 10.0, u'zipcode': u'100'}
{u'students': {u'age': 92.0, u'name': u'joe', u'comments': u'this is a python program'}, u'_id': 11.0, u'zipcode': u'100'}

由此可見,模糊查詢要用到re模塊,查詢條件利用re.compile()函數(shù)

希望本文所述對大家Python程序設(shè)計(jì)有所幫助。

原文鏈接:https://www.cnblogs.com/shaosks/p/5740629.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲国产一区二区三区在线播放 | 国产午夜精品久久 | 国产精品美女久久久久久久久久久 | 欧美一区二区三区精品 | 久久久九色 | 日本a视频在线观看 | 欧美精品综合 | 美女午夜影院 | 国产日韩欧美视频 | 免费毛片a线观看 | 亚洲一区二区三区在线 | 中文字幕 日韩有码 | 在线国产一区二区 | 亚洲国内精品 | 成人综合av | 久久夜视频| 国产精品成人国产乱一区 | 夜夜春精品视频高清69式 | 午夜在线小视频 | 免费观看一级特黄欧美大片 | 亚洲网站视频 | 91精品国产人妻国产毛片在线 | 三级黄色片在线免费观看 | 亚洲第一视频 | 99热在线精品免费 | 精品国产乱码久久久久久丨区2区 | 久久久99精品免费观看 | www日韩 | 欧美精品国产精品 | 四虎影视最新免费版 | 三级无遮挡污在线观看 | 国产精品久久久久久久久 | 毛片黄片| 伊人网站 | 亚州男人天堂 | 久一久久 | 国产成人精品一区二区三区视频 | 在线观看午夜免费视频 | 午夜男人的天堂 | 在线免费看黄 | 国产精品一二区 |