'How to merge two queries on react native firestore

I just want to do leaderboard page. I have 2 collections on firestore users and UserClaims.

I need to merge two queries so I will sum subtotal of userclaims and I need list like:

1 - UserA - 1500
2 - UserB - 1200
3 - UserC - 1000 ...

I tried code below but it returns UserName undefined.

First I'm const 2 blank array. If claims collection have data get all users and push user data and claims data to temp array after that I got these values

allUsers=[{UID:xxxxx, Displayname: UserA,Lastknownposition:[Latitude,longitude]},...]

claims=[{UID:xxx,Price:200,TargetID:yyyy},...]

I need to merge two array based on claims array.

Like left join to claims

mergeData=[{UID:xxx,Price:200,TargetID:yyyy,DisplayName:UserA},...]

How can I do that?

async function getAllClaims() {
        try {
            let claims = (await firestore().collection('UserClaims').get()).docs
            const userTable = []
            const claimTable = []
            if (claims.length > 0) {
                let allUsers = (await firestore().collection('users').get()).docs
                allUsers.forEach(x => userTable.push(x.data()))
                claims.map(x => claimTable.push(x.data()))

                allUsers.map(x => console.log(x.data()))
                const bMap = userTable.reduce((map, item) => map.set(item.UID, item.DisplayName), new Map)
                const result = claimTable.map((item) => (Object.assign({
                    UID: bMap.get(item.UID),
                    UserName: bMap.get(item.DisplayName)
                }, item)))
                result.map(x => console.log(x))
            }
            else (
                Alert.alert(":(", "Daha kazanan yok")
            )

        }
        catch (error) {
            console.log(error)
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source