I'm trying to deploy a simple firebase cloud function using node.js to read a collection, but when deploying it I get this error:
Each then() should return a value or throw promise/always-return
The code is the following
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
let db = admin.firestore();
db.collection('collection').get().then((snapshot) => {
snapshot.forEach((doc) => {
return console.log(doc.id, '=>', doc.data());
});
})
.catch((err) => {
console.log('Error getting documents', err);
});
I tried to add returns but still the error occurs.
return console.log(doc.id, '=>', doc.data());
return console.log('Error getting documents', err);