Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firestore filtering by document reference

I’m trying to filter by document reference in React Native. I’m using react-native-firebase. I want all documents whose field (DocumentReference) is in the provided array:

 const subscriber = firestore()
        .collection('strategyCounts')
        .where(
          'strategy',
          'in',
          user.strategies.map(strategy => {
            return strategy.path;
          }),
        ).onSnapshot(...)

user.strategies looks like this ["/strategies/id", "/strategy/id2"]

strategyCounts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

strategies

users

>Solution :

If you want to filter by document reference, you need to pass DocumentReference objects in the array. So something like:

  user.strategies.map(strategy => {
    return firestore().doc(strategy.path);
  }),

Or (slightly shorter):

  user.strategies.map(strategy => firestore().doc(strategy.path)),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading