Skip to content

[🐛] Firestore orderBy treats FieldPath differently than where #6602

Closed
@Nestoro

Description

@Nestoro

Issue

If an inequality is used for a where query with a FirebaseFirestoreTypes.FieldPath field name, you trigger an exception 'Invalid query'. Seemingly because orderBy handles FirebaseFirestoreTypes.FieldPath field names differently

                    firestore().collection('table')
                        .where(
                            new firestore.FieldPath('address.zipCode'),
                            '>=',
                            options.partialMatch.value,
                        )
                        .where(
                            new firestore.FieldPath('address.zipCode'),
                            '<=',
                            options.partialMatch.value + '\uf8ff',
                        )
                        .orderBy(new firestore.FieldPath('address.zipCode'));

produces:

Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field '`address.zipCode`' and so you must also have '`address.zipCode`' as your first orderBy() field, but your first orderBy() is currently on field 'address.zipCode' instead.

(it is with and without backticks.)

On web, if you escape both, a query like this works.

System:
    OS: macOS 12.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 232.03 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.10.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
    Watchman: 2022.09.26.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: javac 19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0 
    react-native: 0.69.1 => 0.69.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
  • 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:
    • 14.11.1
  • Firebase module(s) you're using that has the issue:
    • firestore
  • Are you using TypeScript?
    • Y & 4.5.4


Metadata

Metadata

Labels

Workflow: Needs ReviewPending feedback or review from a maintainer.help: needs-triageIssue needs additional investigation/triaging.type: bugNew bug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions