One can writeup the following script to run a find in pymongo:
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydb"]
mycol = mydb["mycollection"]
mydoc = mycol.find()
If I want the count of results that went into that last line's find()
result, is there a way to get it without running a separate mongo api call? Or, what is the simplest way to get the count given the code already there.
I do know that you can perform a count by invoking a server aggregate count. Is there a simpler way though that I am missing, or is that separate server operation request necessary?