PyMongo query with projection

projection (optional): a list of field names that should be returned in the result set or a dict specifying the fields to include or exclude. If projection is a list “_id” will always be returned. Use a dict to exclude fields from the result (e.g. projection={‘_id’: False}).

Find more from here


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})

Tags:

Pymongo