I have a google function here with storage onFinalize trigger does 2 things in firestore db
- add the element details into collection elements
- get the size of the element collection
Why is my snapshot.size return undefined?
Console log snapshot returns the correct array result.
exports.elementChange = functions.storage.object().onFinalize((object) => {
var element = {
name: object.name,
time: object.updated
}
db.collection('elements').doc(object.name).set(element)
.then(db.collection('elements').get())
.then((snapshot) => {
console.log(snapshot);
console.log("current size is "+snapshot.size);
return console.log('element total count updated in db');
})
.catch(err => (console.log('Error when finalise element: '+ err)))
// return console.log('finished finalise element');
})