MongoDB – count() method

MongoDB count() Method Use db.collection.count() method to count the number of documents available in a collection. Syntax: db.COLLECTION_NAME.count(query) Example – Count Total Documents Use the following command from mongo shell to count the number of available documents in users collection. > db.users.count(); Output: 8 Example – Count with Find You can also use count() function with other functions like find. > db.users.find({“user_name”:”rahul”}).count() Output: 1

Read More