Have the solution! For anyone looking to do something similar:
The following is my query which both get's me the total doc number for each user (to be placed in the firebase Auth table of my users) and also gathers the most recent 'lastModified' epoch time and places it in a column on the firebase Auth table too. Only issue now is that sorting by something formatted as a date doesn't always seem to work and the way I did it before (moment.unix) didn't seem to like it this time either. So work around is to have a column with epoch time which retool is happy to sort and next to that it's date equivalent.
Here is the JS query:
Where
- getUsers.data is my firebase Auth query.
- userDocList is my firestore document query.
const most_recent_active = getUsers.data.users.map((user) => {
let userID = user.uid
return userDocList.trigger({
additionalScope: {
"userID": userID
}
}).then((data)=>{
let dateModifiedList = data.map(doc => doc.dateModified);
let most_recent_doc_modification = Math.max(...dateModifiedList);
return [userID, most_recent_doc_modification, Object.keys(data).length]
});
});
return Promise.all(most_recent_active);
And here is a screenshot.
