0

I know several keys whose values I want. I want to get them all in one firebase realtime database call. Performance is king. If I know what I want and where it is on the database I should not have to make several queries to get the data.

For example, I can do an update to several paths at once as follows:

const updates = {};

const usermeta = {
    username: username,
       email: user.email,
   lastlogin: unixEpoch,
  signupdate: unixEpoch,
        tier: tierChosen
};

updates[`/account/${uid}`] = usermeta;
updates[`/users/${username}`] = 1;
updates[`/fun/key/to/query`] = "Magic.";
updates[`/slow/key/to/query`] = "Not magic.";
updates[`/fast/key/to/query`] = "Magical.";

rootdb.ref().update(updates)

I know all my updates, make one call, done. Efficient, fast, low latency. How do I do the same on the read side? I don't want to listen to values. I want to retrieve them once. I know where they are, just get them all in one query.

Example, using the update data from above, say I want the data at keys/paths:

`/fun/key/to/query`
`/account/${uid}/username`
`/account/${uid}/signupdate`
`/slow/key/to/query`

How can I get them all on one read call to Firebase Realtime Database?

In the search I did prior to posting I could not find an answer to this. Every solution was to use listeners or make several calls.

ReverseFlow
  • 676
  • 5
  • 28
  • Multi-path updates were added to Firebase for their atomic behavior, not for performance considerations. There is no way to get data from multiple disjunct paths with a single call, nor is there a need for it. Firebase handles all requests over a single web socket connection, and in most scenarios (such as this one) it can pipeline them quite efficiently. Have a look at my answer here for a longer explanation: https://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Nov 17 '21 at 15:09

0 Answers0