I’m trying to create a simple node script to do an export of my firebase auth and storage data. I’ve tried with something like this, but the output is not respecting the async order I’m expecting. Can anyone see if I’m doing something wrong?
// omitting imports
const firestore = admin.firestore();
const main = async () => {
const listUsersResult = await admin.auth().listUsers(10);
await Promise.all(listUsersResult.users.map(async user => {
console.log(user.uid);
try {
const marketsQuerySnapshot = await firestore.collection(`users/${user.uid}/markets`).get();
console.log(marketsQuerySnapshot.size);
await Promise.all(marketsQuerySnapshot.docs.map(async result => {
console.log(result.data());
}));
} catch (e) {
console.error(e);
}
}));
};
main();
As result I’m having all the userId first and then all the markets, but using async I’m expecting to have userId, then markets of that user, and then other userId, etc.
Using the debugger I can see that after const marketsQuerySnapshot = await... the function "return" and the console.log(marketsQuerySnapshot.size); is executed asynchronously, but there is not return. I can't understand.
Thanks