I have coded the below snippet from firestore site and according to my database
but the code isn`t working
i have tried too but nothing else works
the WHERE condition is the main reason isn`t working
else it works fine
const test =() =>{
try {
dob.collection("users")
.where("F_name", "==", true)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
});
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
} catch{
console.log("Erroror")
}
}
Database structure:
3
Answers
I have edited and works fine, but i want to add that list of email_id in the dropdown but doesn`t works
As per the document data, the
F_name
field’s value is a string but you are trying to find a boolean value withwhere("F_name", "==", true)
.The data type must be same when using queries. Try:
Here the value is hard-coded but even if you want to pass user’s input in the query, then you can pass a variable with string value.
If you want to fetch all users from the database you can just do a
get
without any query. But it’s probably not what you want.If you are looking for several user name values you can use the
in
operator (https://firebase.google.com/docs/firestore/query-data/queries#in_not-in_and_array-contains-any)If you are looking for users that has a provided a value for the
F_name
field, then you can use the!=
operator: https://firebase.google.com/docs/firestore/query-data/queries#not_equal_