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?