I am having trouble with my query, i'm trying to use find contains query on a number of fields, here is my code. I would appreciate any help.
def loadContact(search):
myQuery = {'username' : {'$ne' : session['username']},\
'$and' : [{'$or' : [\
{'username' : '/.*' + search + '.*/i'},\
{'surname' : '/.*' + search + '.*/i'},\
{'firstName' : '/.*' + search + '.*/i'},\
{'email' : '/.*' + search + '.*/i'},\
{'company' : '/.*' + search + '.*/i'}]}]}
cursor = db.users.find(myQuery)
payload = []
content = {}
for doc in cursor:
#this is mocked up code for this question so you can see more clearly
content = {'username' : cursor[0], 'firstName' : cursor[1]}
payload.append(content)
return payload
Worth noting the loop does not iterate, the contents of the loop are not of great importance right now if it does not iterate.
from pymongo query not returning results
https://www.wizweb.in
ReplyDeleteWizweb Technology is a leading software development company custom website design, software development, SMS Provider, Bulk sms, transactional sms, promotional sms, mobile app development, Hosting Solution, seo(search engine optimization) and Digital marketing etc.