Firebase real time database compound query combining text and date

I'm trying to make a compound query (combining two children). What I want to do is fetch objects that are older than 5 minutes AND also are of a type.

So I've combined the children type and date into a new child called type_date and I do my query like this:

const now =;
const fiveMinutesMs = 5*60*1000;
const fiveMinutesAgo = now - fiveMinutesMs;

const fiveMinutesAgoQuery = "type_" + fiveMinutesAgo;


Only thing is that it doesn't work. It's giving me results of objects which doesn't even have the type_date child.

Try startAt instead of endAt. I hope it works.

Work with Lists of Data on the Web, Data and Get Realtime Updates. Note: While the code samples cover multiple languages, the text explaining the samples refers to the Web method names. Compound queries. Collection group queries. Query limitations. Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection

EDIT: Oops I was too quick.... it works only if I'm only filtering on the date string but not together with the prepended type which I want...

So this works:

const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = String(fiveMinutesAgoIso);

But not:

const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = "type_" + fiveMinutesAgoIso;

Perform simple and compound queries in Cloud Firestore, You should order your nodes by the timestamp child first and second-order the received items by points on the client-side. This was described� Firebase query by date range. It's important that real time updating is still supported. I also only want to determine the number of all the items that fit the

Just make a Compound queries as doc says :

const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();

ref.where("type", "==", TYPE_YOU_WANT).orderByChild('type').endAt(fiveMinutesAgoQuery).once('value');

How To Query, Filter And Sort Firebase Real-Time Database , Learn how to query the Firebase Realtime Database using events. When you open the firebase-query folder in your favorite text editor, you should You can make complex Database queries with Firebase Query functions combined with� 28,810 In this Firebase tutorial, you will learn how to make a query to the Firebase Real-time Database using Firebase events. After that, you will learn how to sort and filter data using Firebase Order Functions. Finally, I will be showing you how to filter the data using Firebase Query Functions. Making a query to […]

Querying and filtering data | Firestore, Note: While the code samples cover multiple languages, the text explaining the Use the in operator to combine up to 10 equality ( == ) clauses on the same most one array-contains or array-contains-any clause in a compound query: You can create an index through an error message, the console, or the Firebase CLI. To know when your data is committed to the Firebase Realtime Database server, you can use a Promise. Both set() and update() can return a Promise you can use to know when the write is committed to the database. Detach listeners. Callbacks are removed by calling the off() method on your Firebase database reference.

Adding data | Firestore, Getting data � Getting real-time updates � Querying and filtering data Note: While the code samples cover multiple languages, the text explaining merge: true }); including strings, booleans, numbers, dates, null, and nested arrays and objects. Important: Unlike "push IDs" in the Firebase Realtime Database, Firestore� The Firebase Realtime Database can be accessed directly from a mobile device or web browser; there’s no need for an application server. Security and data validation are available through the Firebase Realtime Database Security Rules, expression-based rules that are executed when data is read or written.

Searching Firebase Realtime Database | Tutorials, Searching Firebase Realtime Database - Sending and Managing Data. Multilingual search � Set an index's query language Algolia gives you full-text search, typo tolerance and support for more advanced features like filtering and It does not automatically index an entire nested Firebase database. The Firebase Realtime Database also supports multi-path updates. This means that update can now update values at multiple locations in your database at the same time, a powerful feature which allows helps you denormalize your data. Using multi-path updates, you can add nicknames to both Grace and Alan at the same time:

  • What is your exact data model? What do you store in the type_date field?
  • I store type combined with date in ms for instance "type_1551172088724"
  • Could you provide your data sample?