3

I have the following document:

"players" : [ 
  {
    "id" : userid,
    "name" : "dissident"
  }, 
  {
    "teamId" : teamId,
    "name" : "ink"
  }
]

This is what I tried, but it is not working

this.afs.collection('matches', ref => ref.where('players', 'array-contains', {teamId: teamId}))

2 Answers2

1

Your error is this:

FirebaseError: Function Query.where() called with invalid data. Unsupported field value: undefined (found in field teamId)

This means you passed an invalid value of undefined for teamId in the query, which is invalid. You should debug your code and figure out why teamId is undefined, then fix that.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
1

To solve this, please change the following line of code:

this.afs.collection('matches', ref => ref.where('players', 'array-contains', {teamId: teamId}))

to

this.afs.collection('matches', ref => ref.where('players', 'array-contains', {teamId: teamId, name : 'ink'}))

As you can see, this is actually possible only if you query for the entire object. But be aware, as Doug Stevenson mentioned in his answer if you pass an invalid value of undefined for teamId or for name, you'll always get the error that you are talking about.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193