How to count documents in pymongo

Hey People,
I know this is one of the most basic topics but I cant figure out where im going wrong, trying . count() and .count_documents() and getting the following error:

Cursor' object has no attribute 'count_documents
Cursor' object has no attribute 'count.

the code im using is:

uri = "XXXXXXXXXX"
client = MongoClient(URI); # creating an instance of the client

print(client.sample_training.zips.find(
    {
        "pop" : {"$lt" : 1000}
    }

    ).count_documents())

im feeling quite dumb here…

I figured out the answer, in case anyone else is interested:

uri = "XXXXXXXXXX"
client = MongoClient(URI);

client.sample_training.zips.count_documents(
    {
        "pop" : {"$lt" : 1000}
    }
)
3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.