I am trying to read data from mongodb database as below and running into couple of issues,can anyone provide guidance?
Running into below error, how to fix this?
Is there a way to do a case-insensitive search by regex, I have
"\%train\%"
as below, not sure if this is the right way
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
Errors:
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
UPDATE:
I am not able to verify if the regex works because of the error,how do I fix the error?