I have the following function that tries to read a value in an inventory database and increment it...
app.post('/UpdateInventory', FBAuth,(req,res) => {
const firestore = admin.firestore;
let InventoryRef = admin.firestore().collection('Inventory');
let GetID = InventoryRef.where('IngredientID', '==','BA001').get()
.then(snapshot => {
if (snapshot.empty) {
console.log('No matching documents');
return;
}
snapshot.forEach(doc => {
var CatchDoc = doc.id;
console.log(doc.id, '=>', doc.data());
});
})
admin
.firestore()
.collection('Inventory')
.doc(CatchDoc)
.update({
IngredientAvailability: firestore.FieldValue.increment(10)
});
res.json({CatchDoc});
});
I have set up a variable called "CatchDoc" that is supposedly cathcing the document id that complies with the condition im putting.
The problem is that I always get the following error:
ReferenceError: CatchDoc is not defined
Even though that the console.log output is:
Hm4a9VwDVv1QsYgzKBdl => { IngredientAvailability: 220,
> IngredientImage: 'image.jpg',
> IngredientID: 'BA001',
> IngredientPortion: 30 }
(when i hardcode the Document ID in the .doc reference)
The "Hm4a9....." string is the doc ID I want to save in the CatchDoc variable but I can't...
Can you shed some light ? I have used already the "set" and "let" declaration, they doesnt work neither...thanks a lot ¡