Skip to content

[🐛] 🔥 Query validation may be overly restrictive for inequality filters #8161

@moorea

Description

@moorea

Issue

I believe there may be a discrepancy between the firestore query validation logic in FirestoreQueryModifiers.js and Firebase's official documentation regarding inequality filters and orderBy requirements.

The current validation logic in _validateOrderByCheck() enforces that when using an inequality operator (>, <, >=, <=), the first orderBy() must be on the same field as the inequality filter. If not, the query is rejected with the error:

Invalid query. Initial Query.orderBy() parameter: ${orderFieldPath} has to be the same as the Query.where() fieldPath parameter(s): ${filterFieldPath} when an inequality operator is invoked

However, I do not see this specified anywhere in the official Firestore documentation about query limitations.

Using the firestore query builder, I am able to construct and run a query with an inequality filter that does not match the orderBy.

Screenshot 2024-11-25 at 2 34 39 PM

If I fork this repo and remove this block from _validateOrderByCheck():

if (INEQUALITY[filter.operator]) {
  // Initial orderBy() parameter has to match every where() fieldPath parameter when inequality operator is invoked
  if (filterFieldPath !== this._orders[0].fieldPath._toPath()) {
    throw new Error(
      `Invalid query. Initial Query.orderBy() parameter: ${orderFieldPath} has to be the same as the Query.where() fieldPath parameter(s): ${filterFieldPath} when an inequality operator is invoked `,
    );
  }
}

Then from my app, I'm also able to successfully execute the same query pictured above.

There are discussions in the docs around best practices and performance considerations for optimizing indexes, but this appears to be a performance optimization recommendation rather than a hard requirement.

Proposed Discussion Points

I'm happy to provide additional testing or help investigate further if needed. Let me know if any clarification would be helpful!


Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions