Question: I want to get the total number of users in my Firebase Firestore collection. I can get it easily by writing this code:

```
const [totalUsers, setTotalUsers] = useState(0);
  const [newUsers, setNewUsers] = useState(0);

  useEffect(() => {
    firebase.firestore().collection("Users").get().then((querySnapshot) => {
      const TotalUsers = querySnapshot.size
        setTotalUsers(TotalUsers)

    })
  }, []);

```

But what i want is to get the total number of users with a condition such as the following:

```
   // this is not working, its not showing any results back.
  useEffect(() => {
    firebase.firestore().collection("Users").where("usersID","!=","101010").get().then((querySnapshot) => {

      querySnapshot.forEach((doc) => {
        const TotalUsers = doc.size
        setTotalUsers(TotalUsers)
      })

    })
  }, []);

```

But the above code is not working and isn't returning any results.

How can I get the total number of documents in a collection in firebase firestore with a where query?

Answer: 
Firestore has just launched a native COUNT function which is very cost-efficient. Please refer to the official [documentation](https://firebase.google.com/docs/firestore/solutions/aggregation) for more information. You can also refer to this [blog](https://cloud.google.com/blog/products/databases/aggregating-data-with-firestore).
Further to @Chaitra's answer.

Using this code below will give you a count of documents with a query.

```
import { collection, Firestore, getCountFromServer, query, where } from '@angular/fire/firestore';
    {...
  totalUsers: any;

  constructor(
  private fs: Firestore
  ){}

  onInit() {
   this.getUserCount()
  }

  async getUserCount() {

    const usersCol = collection(this.fs, `users`)

    const chkQuery = query(chkCol, where('usersID', '!=', '101010'))

    const count = await getCountFromServer(chkQuery)

    this.totalUsers = (await count).data().count

    }
    ...}

```

Then in your HTML template:

```
<h2>User Count: {{totalUsers}}</h2>

```