How to count the total number of documents in mongodb


 description

View the total number of documents in the test collection in mongodb

 command

db.getCollection('test').aggregate([{$count:"result"}])

 parameter

aggregate :  Use the aggregation pipeline to perform aggregation operations
$count :  count the total number of documents

 result

{
    "result" : 200
}

I hope to help every developer quickly find the commands they need. Of course, you can also add your own commonly used commands for easy searching.