I'm working on creating a Firestore database hosted through a web application. I want to query all the docs in my "tasks" collection and grab the ones that aren't labeled extra who have the "dept" field value of "MUSH".
Here is an excerpt of my code:
import { initializeApp } from "firebase/app";
import { getFirestore,
collection,
getDocs,
query,
where
} from 'firebase/firestore';
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const mush = query(collection(db, "tasks"), where("extra", "!=", "true"), where("dept", "==", "MUSH"));
const mushList = [];
const innerMushList = [];
const weekdayList = []
try {
const mushSnapshot = await getDocs(mush);
console.log("checkpoint 1");
mushSnapshot.forEach((doc) => {
console.log("checkpoint 2");
const task = doc.get("task");
innerMushList.push(task);
if (doc.get("monday") != null) {
weekdayList.push("Mon");
}
else if (doc.get("tuesday") != null) {
weekdayList.push("Tue");
}
else if (doc.get("wednesday") != null) {
weekdayList.push("Wed");
}
else if (doc.get("thursday") != null) {
weekdayList.push("Thu");
}
else if (doc.get("friday") != null) {
weekdayList.push("Fri");
}
else {}
innerMushList.push(weekdayList);
weekdayList = [];
const time = doc.get("time");
innerMushList.push(time);
const staff = doc.get("staff");
innerMushList.push(staff);
mushList.push(innerMushList);
innerMushList = [];
});
}
catch(error) {
console.log(error);
}
When I run the code in my browser, "checkpoint 1" appears in my console. "Checkpoint 2", however, doesn't appear at all. The console doesn't present me with any errors. Any ideas on how to fix this? When I run console.log(mushSnapshot) in the place of checkpoint 1, the console prints out an object that is labeled "Mh". Please see the picture attached.