I currently try to use firebase for web and get data from Firestore. This is my code for bring the all my data from Firestore.
function FireStoreGetAllData() {
let db = firebase.firestore();
let dataMap = new Map();
db.collection("User").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
let dataset = new Map();
let docId = doc.id;
let docdata = doc.data();
let firstName = docdata.first;
let lastName = docdata.last;
let bornData = docdata.born;
dataset.set('first', firstName);
dataset.set('last', lastName);
dataset.set('born', bornData)
dataMap.set(docId, dataset);
});
});
console.log('dataSet',dataMap.entries());
return dataMap;}
Problem is the "dataMap" always return null every time. I debug this issue and find out that "db.colloction" is execute the code after "return dataMap".
What am I missing?
Aucun commentaire:
Enregistrer un commentaire