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,

30th May 2022, 2:56 PM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
4 Respuestas
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);
31st May 2022, 9:01 AM
Emeh Matthew
Emeh Matthew - avatar
0
Let me try this
31st May 2022, 5:51 PM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
Would it work regardless of the user id
31st May 2022, 5:51 PM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
Yes it should
31st May 2022, 6:23 PM
Emeh Matthew
Emeh Matthew - avatar