Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the $project (aggregation) API for Pymongo?

Tags:

python

mongodb

I'm rather new to MongoDB, I can find some commands in shell to execute my query, however, I can not find a proper function in PyMongo API manual.

For example, I would like to project some of the fields of the document to a new document. I suppose the $project could do it, but there is no such support in Pymongo. How could I execute the same query both in shell and Python? For example:

db.books.aggregate( [ { $project : { title : 1 , author : 1 } } ] )
like image 204
user3329081 Avatar asked Oct 25 '25 05:10

user3329081


1 Answers

For projecting you may use the query as

db.books.aggregate([{'$project':{ 'title':'$title', 'author':'$author'}}])
like image 134
Arun K Avatar answered Oct 26 '25 17:10

Arun K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!