Caa*_*azu 1 python pymongo python-2.7 mongodb-query
在添加$ or选项之前,我似乎无法使其与pymongo一起使用。我是否错过了一些明显的东西
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
直接在mongo中运行以下内容可以工作,但在切换到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)
一旦我添加了$或它需要用引号引起来,就应该早点解决这个问题。所以这工作:
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)