0

I am currently fetching notifications from a google firebase realtime db collection based on a users id. I also need to filter the snapshot to ensure that only notifications created in the last 7 days are returned. Would appreciate any help

export const getNotifications = async (uid) => {
    const fb = new Firebase();
    const notifSnap = await fb.notifications().orderByChild('user_id').equalTo(uid).once('value');
    return notifSnap?.val() || {};
  };

Have been testing for a bit.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. So in your case that could be something like `"userid_timestamp": "asdas7432asd_1675214529900"` and you'd then order/filter on that. For more examples of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Feb 01 '23 at 01:21

0 Answers0