react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Error (firestore/failed-precondition) when chaining two Where function calls via Firestore.

Open jojonarte opened this issue 8 years ago • 5 comments

Issue

I have this code below, what I was trying to accomplish was to chain a where on a collection query via firestore. Trying to chain two wheres where one is an '==' while the other is an '>=' causes (firestore/failed-precondition) issue.

Each document on that collection looks like below:

reservationDocument: {
   dateTime: TimeStamp,
   deleted: boolean,
   duration: number,
}

While my code to test the query was below:

import firebase from 'react-native-firebase';

const query = () => {
    firebase
          .firestore()
          .collection('reservations')
          .where('deleted', '==', false)
          .where('dateTime', '>=', new Date())
          .get()
          .then(data => console.log('DATA', data))
          .catch(err => console.error(err));
};

Environment

  1. Application Target Platform:

Both

  1. Development Operating System: OS: macOS High Sierra 10.13.5

  2. Build Tools: Xcode: Xcode 9.4 Build version 9F1027a Android Studio: 3.1 AI-173.4819257

Node: 8.11.2 Yarn: 1.7.0 npm: 6.2.0 Watchman: 4.9.0 4. React Native version: react: 16.3.1 => 16.3.1 react-native: 0.55.4 => 0.55.4 5. React Native Firebase Version: "react-native-firebase": "^4.3.8", 6. Firebase Module: firestore,

  1. Are you using typescript? no

jojonarte avatar Aug 29 '18 05:08 jojonarte

Potentialy related https://github.com/invertase/react-native-firebase/issues/1439

Ehesp avatar Aug 30 '18 18:08 Ehesp

Doesn't worked if combine both conditions or either one.

.where("date", ">=", date1MonthAgo.getTime()) .where("date", "<=", Date.now())

ggdegreat avatar Dec 08 '18 07:12 ggdegreat

I've gone through every Date based querying scenario I could think of plus the ones linked in the other issues and I've been unable to reproduce any errors on either platform;

You can view all the tests I added for this here: https://github.com/invertase/react-native-firebase/commit/6bc668c8ab9e1e3cf3a990348a9ac9f4596f6bd8

This may have been an issue with the Native SDKs or an earlier release but everything appears to be fine now.

I'll go ahead and close this issue now. I'd suggest if anyone has an issue like this again submit a PR with a test that fails - the groundwork for this has been done in that commit.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Jan 04 '19 22:01 Salakar

This solution worked for me

https://github.com/invertase/react-native-firebase/issues/815#issuecomment-465741365

stevenheffner avatar Apr 13 '19 18:04 stevenheffner

This usually means that you either:

  1. Need to change your firestore rules or most likely,
  2. You need an index on the where field. You can create it manually in the firebase console or run this in a terminal and you will find a link to create it automagically: adb logcat *:W

The link will be something like this: Caused by: io.grpc.StatusException: FAILED_PRECONDITION: The query requires an index. That index is currently building and cannot be used yet. See its status here: https://console.firebase.google.com/v1/r/project/...

leron8 avatar Jun 11 '20 11:06 leron8