Categories
JavaScript Answers

How to get all count of Mongoose model?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *