Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Each then() should return a value or throw, promise/always-return

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);

like image 331
Francesco Avatar asked Feb 01 '26 18:02

Francesco


1 Answers

You are returning inside a function :) it doesn't count, you must add it here:

db.collection('collection').get().then((snapshot) => {
  return snapshot.forEach((doc) => {
    return console.log(doc.id, '=>', doc.data());
  });
})
.catch((err) => {
  console.log('Error getting documents', err);
});
like image 156
Renaldo Balaj Avatar answered Feb 03 '26 06:02

Renaldo Balaj