Q:

MongoDB querying with Python

I'm trying to build mongoDB query based on python's dictionaries.
The problem that a key should be unique in dicts.
See the example
MongoDB data:
{
        "_id" : ObjectId("4dcd3ebc9278000000005158"),
        col1 : 'foo'
}
{
        "_id" : ObjectId("4dcd3ebc9278000000005159"),
        col1 : 'bar'
}

Python code:
dict = {'col1': 'foo'}
dict.update({'col1': 'bar'})

db.test.find(dict)

shows only one line with col1=='bar'
>>> dict
{'col1': 'bar'} 

How can I build the right MongoDB query using dictionaries (or anything) which does not need to have unique keys.
Thanks!

A:

Are you looking for documents where 'col1' is either 'foo' OR 'bar'?
If so, then you want db.test.find({'col1': {'$in': ['foo', 'bar']}});
To explain, that query matches documents where the value of col1 is in the list ['foo', 'bar'].
Advanced mongodb queries are documented here: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24in

