gpt4 book ai didi

python - 如何对 mongodb 进行不区分大小写的正则表达式搜索?

转载 作者:太空宇宙 更新时间:2023-11-04 04:30:47 33 4
gpt4 key购买 nike

<分区>

我正在尝试从 mongodb 数据库中读取数据,但遇到了几个问题,有人可以提供指导吗?

  1. 遇到以下错误,如何解决?

  2. 有没有办法通过正则表达式进行不区分大小写的搜索,我有如下"\%train\%",不确定这是不是正确的方法

from pymongo import MongoClient
import os,pymongo
dbuser = os.environ.get('muser', 'techauto1')
dbpass = os.environ.get('mpwd', 'techpass')
uri = 'mongodb://{dbuser}:{dbpass}@machine.company.com:27017/techautomation'.format(**locals())
client = MongoClient(uri)
db = client.techautomation.tech_build_audit
try:
#db.tech_build_audit
myCursor = db.collection.find({"chip" : "4377","branch" : "\%train\%"}).sort({"_id":-1})
print myCursor

except pymongo.errors.AutoReconnect, e:
print e

错误:

Traceback (most recent call last):

File "parseplist.py", line 11, in

myCursor = db.collection.find({"chip" : "4377","branch" : "%peaceB%"}).sort({"_id":-1})

File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 703, in sort keys = helpers._index_list(key_or_list, direction)

File "/Library/Python/2.7/site-packages/pymongo/helpers.py", line 52, in _index_list

raise TypeError("if no direction is specified, "

TypeError: if no direction is specified, key_or_list must be an instance of list

更新:

由于错误,我无法验证正则表达式是否有效,我该如何修复错误?

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com