1

Im trying to create a query to get a firestore collection/doc where userId is equal to the current userId or current userId is equal to contributorsId.

export default compose(
  connect(mapStateToProps),
  firestoreConnect((props) => {
    if (!props.auth.uid) return []
    return [
      {
        collection: 'canvases',
        orderBy: ['createdAt', 'desc'],
        where: [
          ['userId', '==', props.auth.uid] || ['contributors', 'array-contains', props.auth.uid]
        ],
      }
    ]
  })
)(CanvasSelector);

I want it to give me all docs where the statements are true. But it only returns the first one. If I choose to only include either one of the queries ("where") they both work and returns the correct docs.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Jonaaust
  • 11
  • 5
  • 1
    Firestore doesn't support logical OR queries. You have to perform each query separately, and merge their results in the client code. – Doug Stevenson Jul 31 '19 at 19:36

1 Answers1

2

I think you are not passing the queries correctly Try like this -

where: [
      ['userId', '==', props.auth.uid],
      ['contributors', 'array-contains', props.auth.uid]
],

Also make sure to create a composite index when you use the equality operator (==) with a range or array-contains clause (<, <=, >, >=, or array-contains)

Check out how to create one here https://firebase.google.com/docs/firestore/query-data/indexing

TheWizardJS
  • 151
  • 9