I have two collections section1
and section2
. Collection section2
has a field doc_id
, it's a reference
type field and represents a relationship between section1
and seciton2
.
I want to retrieve data from section2
for given value for doc_id
field. check the sample codes it works fine when I filter data with any other field such as district
. But it does not work with reference field type fields
This gives expected result
const getDocumentData = async () => {
const q = query(
collection(db, "section2"),
where("district", "==", "dhanbad")
);
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
});
Code works but I don't get the values. It returns null.
const getDocumentData = async () => {
const q = query(
collection(db, "section2"),
where("doc_id", "==", "H0ovBXfrwen32Xb4Ig9A")
);
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
});