clwen
clwen

Reputation: 20929

PyMongo find by multiple values

In Mongo shell, one can find documents for multiple values in the same field by

coll.find({blah: {$in: ["foo", "bar"]}});

Just wondering how to do this in PyMongo? Tried this but doesn't work:

coll.find({'blah': ['foo', 'bar']})

Upvotes: 2

Views: 2236

Answers (1)

vaultah
vaultah

Reputation: 46593

Add quotes around field name and $in operator:

coll.find({'blah': {'$in': ["foo", "bar"]}})

Upvotes: 3

Related Questions