I want to get a data from Firebase. But I know Firebase use forEach to search a data in the database.
db.collection('users').get()
// eslint-disable-next-line promise/always-return
.then((snapshot) => {
snapshot.forEach((doc) => {
console.log(doc.id, '=>', doc.data());
myData.push(doc.data().first);
});
const title = myData.find( e => e === 'Dennis');
res.render('index', {title});
// return null;
})
.catch((err) => {
console.log('Error getting documents', err);
});
you can see forEach will search every doc.data().first
in the database.
but I thought this is a very inefficient way to search for data in the database. I want forEach stops when it finds the data I want to get.