0

I'm calling the firebase store via PHP, when I call:

        $query = $collection
            ->where('c', '=', $vars['cid']);

or

        $query = $collection
            ->where('t', '>', $params['lastSync']);

It works fine.. however when I combine it stops working:

        $query = $collection
            ->where('c', '=', $vars['cid'])
            ->where('t', '>', $params['lastSync']);

How can I solve this?

Thank you so much! Maarten

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Maarten Raaijmakers
  • 615
  • 2
  • 8
  • 20

1 Answers1

0

Since "stops working" is not specific detail, assumption is it gives an error message, whether seen or unseen.

According to firebase doc on compound queries [emphasis added]:

Compound queries

You can also chain multiple where() methods to create more specific queries (logical AND). However, to combine the equality operator (==) with a range or array-contains clause (<, <=, >, >=, or array_contains), make sure to create a composite index.

From firebase doc on indexing:

If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error. The error message includes a direct link to create the missing index in the Firebase console.

DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15
  • I unfortunately don't get an error message back so it's hard to tell at the moment. I've read that part, however I copied their example and it doesn't work as they give it. This is also the example posted above. How do I catch this error? As it's not output right now by the official library for php. – Maarten Raaijmakers Mar 20 '19 at 18:23
  • The other, even simpler, explanation is that there are no documents that meet both criteria. (Changing assumption to: "working" means results are returned). – DinoCoderSaurus Mar 20 '19 at 19:55
  • There definitely should be results. – Maarten Raaijmakers Mar 21 '19 at 10:07
  • Ok to recap: composite index exists; no errors thrown (firebase, php, webserver, browser console); expect results. Who are the "they" in _as they give it_? Do "they" have a support area that could give more help? Is it because `t` is a datetime? FYI [show all php errors and warnings](https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings/5438125#5438125) – DinoCoderSaurus Mar 21 '19 at 11:54
  • You were right in the end about the indexing. I run the script standalone and then did get the message. Thank you! – Maarten Raaijmakers Mar 23 '19 at 14:01