문제

I'd like to query a mongo collection for records which either don't have a value for a field named 'scheme', or explicitly have the value 'http' for 'scheme'. Sounds pretty easy, but this problem has proved more complex than it first appears.

Since db.collection.find({'scheme': None}) returns all records where 'scheme' is undefined (no index field), I initially assumed the following would work:

db.collection.find({'scheme': {'$in': ['http', None]}})

However, this seems to exclude values in which 'scheme' is undefined, so I can only assume it is searching for records where scheme is either 'http', or explicitly defined to be None. This seems to be a bit counterintuitive, but there we have it. My second attempt was the following:

db.collection.find( {'$or': [{'scheme': {'$exists': False}}, {'scheme': 'http'}]})

This also excludes result where scheme is undefined. This time, I can't even think of a logical reason why this is failing.

Any ideas why this is failing, and how I can get it to work as desired?

Thanks

EDIT: Just thought I'd note that I'm performing this query through Python (pymongo), which explains the None (over Javascript's null)

도움이 되었습니까?

해결책

Resolved: This is apparently an issue of my version of mongodb (1.4.4), the issue is solved in 1.6.5.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top