57359

How to retrieve range of data in firebase

Question:

I have user's data which have uuid as their key. I want to send mail to each user, But I don't want to send them mail all together so I want to retrieve range of user.

For example, I have 1000 user's now I want to send mail to range 1-100 user then 101-200 , 201-300 and so on. How can I achieve this? I have seen startAt() and endAt() functions, but my question is I don't know user key at the beginning and at the end. So I won't be able to retrieve range from that way.

Answer1:

To get the first 100 users you'd do a query on:

query = ref.orderByKey().limitToFirst(100)

Then as you process the users, keep track of the last key you've processed:

vast lastSeenKey; query.once("value", function(snapshot) { snapshot.forEach(function(userSnapshot) { lastSeenKey = userSnapshot.key; }); });

And then to load the next 100 users, you make the query start at the last key you've seen:

query = ref.orderByKey().startAt(lastSeenKey).limitToFirst(101)

You'll note that we retrieve one extra item here, since the first user in this query will be the same as the last user in the previous query.

Recommend

  • Angularfire - Firebase query / sync first x items in document
  • Firestore order by two fields
  • beginAt, endAt using index instead of priority
  • Android Firebase query data
  • Firebase always returning all the rows
  • setPriority() sometimes don't seem to fire startAt().endAt().on(“child_added”)
  • Angular ui.grid infinite scroll is not being called second time onwords
  • multi query and pagination with firestore
  • TelephonyManager crashing on android studio
  • How do I get an Option instead of an Option from a Diesel query which only returns 1 or 0 records?
  • ASP Error 0223 - TypeLib Not Found, intermittent, resolved after IIS restart
  • Socket io in node app on google app engine
  • Updating and removing unique join relationships in CakePHP
  • EntLib Way to Bind “Null” Value to Parameter
  • Monotouch crashes with NullReferenceException on non nullable object
  • Access object instance inside an event handler
  • Extract All Possible Paths from Expression-Tree and evaluate them to hold TRUE
  • How to get links to open in the native browser in iOS Meteor apps?
  • Django model inheritance, filtering models
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Ajax Loaded meta Tags
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Xamarin Forms - UWP Fonts
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Is possible to count alias result on mysql
  • output of program is not same as passed argument
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Cassandra Data Model
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Statically linking a C++ library to a C# process using CLI or any other way
  • Display Images one by one with next and previous functionality
  • Why winpcap requires both .lib and .dll to run?
  • Arrays break string types in Julia
  • SQL merge duplicate rows and join values that are different
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Benchmarking RAM performance - UWP and C#
  • How to get NHibernate ISession to cache entity not retrieved by primary key