Database

How do you count rows in MongoDB? It is easy to count records.

Use the count method

> db.books.find().count()
4
> db.books.find({"title": "Book"}).count()
0
> db.books.find({"title": "Book Title"}).count()
1
> db.books.find({"category": "Fiction"}).count()
2

You can also you multiple key terms on find

> db.books.find({"category": "Fiction", "title": "Book Title"}).count()
1