0

So I have a list of paragraphs in my firebase realtime database

enter image description here

And I want to randomly retrieve multiple of them based on random array values like

const x = [0, 2, 5].

I retrieve data with get()

const parasnapshot0 = await get(child(dbRef, `paragraphs/${x[0]}`));
const parasnapshot1 = await get(child(dbRef, `paragraphs/${x[1]}`));
const parasnapshot2 = await get(child(dbRef, `paragraphs/${x[2]}`));

The problem with this is it won't scale well and the query made to firebase would hog on the network. Is there a way to make 1 query and retrieve a list/json of the items I need? Something like:

const parasnapshot2 = await get(child(dbRef, `paragraphs/${x[0]},${x[1]},${x[2]}`));
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mir Adnan Siraj
  • 67
  • 1
  • 12
  • 1
    "The problem with this is it won't scale well and the query made to firebase would hog on the network" It actually doesn't, as Firebase pipelines the requests over a single web socket connection. I recommend checking the network panel of your browser's debugging tools, and my answer here: 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 Aug 26 '21 at 20:04
  • Thanks I didn't actually know about the pipelining – Mir Adnan Siraj Aug 27 '21 at 07:03

0 Answers0