PyMongo query with projection

sajith picture sajith · Mar 31, 2014 · Viewed 20.8k times · Source

what is the PyMongo way for db.collection.find(criteria, projection).I cant find any doc for specifying projection to the collection.find() method

Answer

Carlos Rodriguez picture Carlos Rodriguez · Apr 4, 2014

Is equeal to mongo shell, but the condition between ""

db.foo.find({"field1.field2":123},{"field1":{"$elemMatch":{"field2":123}}})

db.foo.update({"_id":3,"field1.field2":1},{"$set":{"field1.$.field2":2}})

Or if you mean to projections to show any fields, is equal to mongo shell

db.foo.find({"field1.field2":123},{"field1.field2":1, "_id":1})