Mongodb is a document-oriented NoSQL database which is non-relational DB. Mongodb is a schema-free database which is based on Binary JSON format. It is organized with a group of documents (rows in RDBMS) called collection (table in RDBMS). The collections in mongodb are schema-less.
PyMongo is one of the MongoDB drivers or client libraries. Using the PyMongo module we can send requests and receive responses from
Count the number of Documents using Python
Method 1: Using count()
The total number of documents present in the collection can be retrieved by using
Example : Count the number of documents (my_data) in the collection using
The number of documents in collection : 8
Method 2: count_documents()
Alternatively, you can also use count_documents() function in pymongo to count the number of documents present in the collection.
Example : Retrieves the documents present in the collection and the count of the documents using
Total number of documents : 8
- Create XML Documents using Python
- Update all Documents in a Collection using PyMongo
- Get all the Documents of the Collection using PyMongo
- Create a database in MongoDB using Python
- 3D Plotting sample Data from MongoDB Atlas Using Python
- How to fetch data from MongoDB using Python?
- How to access a collection in MongoDB using Python?
- Drop Collection if already exists in MongoDB using Python
- How to create index for MongoDB Collection using Python?
- Indexing in MongoDB using Python
- Aggregation in MongoDB using Python
- How to import JSON File in MongoDB using Python?
- Web Scraping CryptoCurrency price and storing it in MongoDB using Python
- MongoDB and Python
- Guide to Install MongoDB with Python | Windows
- MongoDB Python | Insert and Update Data
- MongoDB python | insert(), replace_one(), replace_many()
- MongoDB python | Delete Data and Drop Collection
- Python MongoDB - Find
- Python MongoDB - Sort
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : soniyanagaraj30