Im trying to get data from a collection where the information inside it is: owner_uid
members collection
and query my user collection if it exist there , if so to map it in array
users info collection
is there a way to query this?
also tried to map the the “members collection” and then try to query comparing to the array with no success , is it possible?
the code i tried:
const { chh } = props.route?.params; //current house hold
const [members, setMembers] = useState([]);
const [chhUsers, setChhUsers] = useState([]);
useEffect(() => {
const q = query(collection(db, `households/${chh.title}/members/`));
const querySnapshot = getDocs(q).then((querySnapshot) => {
setChhUsers(querySnapshot.docs.map((doc) => doc.data()));
});
console.log(chhUsers);
}, []);
useEffect(() => {
setTimeout(() => {
const userdb = collection(db, `users`);
const q = query(userdb, where("owner_uid", "==", chhUsers));
const querySnapshot = getDocs(q).then((querySnapshot) => {
setMembers(querySnapshot.docs.map((doc) => doc.data()));
});
console.log(members);
}, 2000);
}, []);
what i get from chhUsers:
Array [
Object {
"owner_uid": "4g8urzWb6RPP44ak9iPIlZidWDo2",
},
]
but the query of console.log(members); return empty
if i change the chhUsers in const q = query(userdb, where(“owner_uid”, “==”, chhUsers));
it return me the info