1

I can't seem to get this to work with pymongo it was working before I added the $or option. Am I missing something obvious with this

dataout = releasescollection.find( { $or: [{"l_title":{"$regex": "i walk the line", "$options": "-i"}}, {"artistJoins.0.artist_name":{"$regex": "Johnny Cash", "$options": "-i"}}]}).sort('id', pymongo.ASCENDING).limit(25)

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "discogs.py", line 51 dataout = releasescollection.find( { $or: [{"l_title":{"$regex": "i walk the line", "$options": "-i"}}, {"artistJoins.0.artist_name":{"$regex": "Johnny Cash", "$options": "-i"}}]}) ^ SyntaxError: invalid syntax

Running the below directly in mongo works but I'm missing something in the switchover to python

db.releases.find( { $or: [{"l_title":{"$regex": "i walk the line", "$options": "-i"}}, {"artistJoins.0.artist_name":{"$regex": "Johnny Cash", "$options": "-i"}}]}).sort({'id':1}).limit(25)

1 Answer 1

8

Should've relized this far sooner, once I added the $or it needs to be in quotes. So this works:

dataout = releasescollection.find( { "$or": [{"l_title":{"$regex": "i walk the line", "$options": "-i"}}, {"artistJoins.0.artist_name":{"$regex": "Johnny Cash", "$options": "-i"}}]}).sort('id', pymongo.ASCENDING).limit(25)

Sign up to request clarification or add additional context in comments.

1 Comment

You found the solution but, for those who will explore this in the future, quotes must enclose the $orexpression as indicated in the documents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.