Skip to content

πŸš€ [firestore] Allow single filter in and() or() queries.Β #8418

Open
@ycmjason

Description

@ycmjason

Firstly, thank you so much for working on this library. My apps are not possible without you guys! πŸ™‡β€β™€οΈ Big ❀️ guys!

What feature would you like to see?

In my apps, there are some occasions where the queries within and() / or() changes based on conditions. For example

    query(
      userCollection,
      and(
        where('happy', '>', 10),
        ...(minSadness !== undefined ? [where('sadness', '>', minSadness)] : []),
      ),
    ),

Currently the API wouldn't support this usecase as it will throw:

https://github.com/invertase/react-native-firebase/blob/main/packages/firestore/lib/FirestoreFilter.js#L45-L47

I do have a work around by wrapping the and function:

import {  and as firestoreAnd } from '@react-native-firebase/firestore';

const and: typeof firestoreAnd = (...queries) => {
  if (queries.length === 1) return queries[0];
  return firestoreAnd(...queries);
};

Ideally this library would supprot this?

P.S. I haven't checked, but I have the impression that this is supported in the official web modular api. (not 100% sure... don't quote me on that xD)

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