1

I am trying to display the total registered users in the admin panel.

Below is my code to get the total count

exports.getcount = async (req, res) => {
  Client.count({}, function (err, count) {
    console.log("Number of users:", count);
    res.status(200).json({
      message: `Registered  Clients ${count}`,
    });
  });
};

In my client schema, I have an isDeleted field that is either true or false. In my total count, I just want to return those clients which contain isDeleted:false.

Kartikey
  • 4,516
  • 4
  • 15
  • 40
Shehryar Tanoli
  • 393
  • 2
  • 4
  • 17

1 Answers1

2

Instead of .count(), which is deprecated (see here ), you could use .countDocuments({ isDeleted: false }).

countDocuments accepts a filter that will match documents in your database collection. Here are the docs

AhmCho
  • 380
  • 4
  • 12