Note: This is not a duplicate question, please read till the end and see the included image.
I have a nested object and an array field inside my collection/document in Firestore.
Main categories
- Drinks
- Snacks
Items for Drinks are
- (Water, Energy, Milk, ...)
Items for Snacks are
- (Chips, Biscuits, Corn, ..)
The user may subscribe to both categories for multiple items with an expiration date:
- Drinks->Energy
- Drinks->Milk
- Snack->Chips
I want to update the [expDate] field where [name] is equal to drinks and [type] is equal to [energy]
I have explored Firestore documentation more importantly compound queries in Cloud Firestore and read so many article(s) and questions on stackeoverflow but I couldn't find my answer, below is part of my code which I tr.
db.collection(this.dbName)
.where("name", "==", "drinks")
.where("subscriptions.data.type", "==", "energy")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
let data = doc.data();
if (data.email == email) {
let subscriptions = data.subscriptions;
subscriptions.forEach((subscription) => {
if (subscription.name == productName) {
let prodTypes = subscription.data;
prodTypes.forEach((prodType) => {
if (prodType.type == itemType) {
let docRef = fb.db.collection(this.dbName).doc(email);
fb.db
.collection(this.dbName)
.doc(email)
.update(docRef, {
subscriptions: [
{
data: [
{
expDate: expiration,
type: itemType,
},
],
name: productName,
},
],
});
}
});
}
});
}
});
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
I don't get any console log result for the above query.