How to get all count of Mongoose model?

Sometimes, we want to get all count of Mongoose model.

In this article, we’ll look at how to get all count of Mongoose model.

How to get all count of Mongoose model?

To get all count of Mongoose model, we can use the model count method.

For instance, we write

userModel.count({}, (err, count) => {
  console.log("Number of users:", count);
})

to call useModel.count to get the count of the items in the collection mapped to userModel.

We get the count from the count parameter in the callback.

Conclusion

To get all count of Mongoose model, we can use the model count method.