With the following async function I get data from a firebase firestore instance:
export async function getSomething(db, id) {
db.collection('someting').doc(id).get().then((doc) => {
if (doc.exists) {
return doc.data();
}
throw new Error('No such document!');
}).catch((error) => {
throw new Error('err', error);
});
}
I called this function like:
getSomething(db, this.id).then((data) => {
console.log(data); // data is empty here
}).catch((err) => {
console.log(err);
});
The issue is, that on the data
from the then
function is empty.
How can I get the data from the getSomething
function? Is returning the data not enough?