【发布时间】:2014-09-27 08:58:28
【问题描述】:
我想搜索 MongoDB,以便只获得在某个配置中同时在键中找到所有 x 的结果。
collected_x = ''
for x in input:
collected_x = collected_x + 're.compile("' + x + '"), '
collected_x_cut = collected_x[:-2]
cursor = db.collection.find({"key": {"$all": [collected_x_cut]}})
这并没有带来预期的结果。如果我自己输入多个x,它就可以了。
cursor = db.collection.find({"key": {"$all": [re.compile("Firstsomething"),
re.compile("Secondsomething"),
re.compile("Thirdsomething"),
re.compile("Fourthsomething")]}})
我做错了什么?
【问题讨论】:
标签: python regex mongodb pymongo