Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top