1

database image

I have a firebase database looking like this would like u get all calendar events objects that contains a specific user emails by the email like: "admin@live.dk"

I need this so I can show each user what events they have joined in the calendar

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Your current data structure makes it easy to find the users for a specific date/event. It does not make it easy to find the events for a specific user. To allow that you will need to add an additional data structure, that sort of inverts what you currently have: mapping each user (UID/email) to their list of events. For examples of this, see https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value, https://stackoverflow.com/questions/27207059/firebase-query-double-nested and https://stackoverflow.com/questions/41527058/many-to-many-relationship-in-firebase – Frank van Puffelen Apr 08 '21 at 23:30
  • thanks alot for it :) i will take a look at it – Mathias Vrist Bramstorp Apr 09 '21 at 06:46
  • const [arr, setArr] = useState([]); firebaseDB .database() .ref("calendar/events") .on("value", (snapshot) => { let data = []; snapshot.forEach((child) => { data.push(child.val()); }); setArr(data); }); then you can do this var returned = []; arr.forEach((snapshot)=>{ if(snapshot.0.users.0.user_email==="admin@live.dk"){ returned.push(snapshot); } }); – Dennis Apr 09 '21 at 07:54
  • testing it at the moment by cant get the this to work cus of "0" if(snapshot.0.users.0.user_email==="admin@live.dk") – Mathias Vrist Bramstorp Apr 09 '21 at 21:56

0 Answers0