0
How to write items with a particular key value from Firebase Realtime database
User{ Aby12fvjg7ngf89jtd4Rf6ubu6dc{ Referralcode : afchdeww12, Refercode : Fhb0VP7xje97, referno : 0, } } Am trying to get how many users "referralcode" match any users "refercode", For example, this first user "refercode:" is "Fhb0VP7xje97" I want to know how many users from the whole database has this referral code in their "referralcode" value, and save the number to the "referno" value, so that the number of people referred by users would be visible to the user,
4 ответов
0
I don't think there's need to update the referno everytime.In this case it's a redundant key. You could just use a filter function to find how many users have "Fhb0VP7xje97" as their refercode
Example:
let referrals = users.filter(user => user.Refercode === "Fhb0VP7xje97")
console.log(referrals.length);
0
Let me try this
0
Would it work regardless of the user id
0
Yes it should