2

I need to perform a query to return a list of documents associated with one particular user id

database structure

this works because I´m sending exactly the same map.

firestore.collection('conversations').where('users', 'array-contains', {id: 1, username: 'john')

this doesn´t work I assume because I´m only sending the id

firestore.collection('conversations').where('users', 'array-contains', {id: 1})

is it possible to do that or I will have to "manually" filter all records? thank you!

handsome
  • 2,335
  • 7
  • 45
  • 73

1 Answers1

2

array-contains doesn't support querying against a field of an object in an array as of now. But you can restructure your data so that you can make use of it. Please see the below links for answers already available on SO regarding the same question.

Firestore to query by an array's field value

How to query documents containing array of objects in Firestore collection using whereArrayContains() filter on Android?

denniskbijo
  • 576
  • 3
  • 10
  • thanks @denniskbijo what´s your suggestion to restructure? I have now a channels collection and a messages collection. I know how to get all messages for a given conversation (because I have the id) but I still need to somehow list all the channels that the user is part of. one option is to just get all channels and make the filter on the client side. this is expensive and will be more complicated as the list of channels grow. – handsome Jun 05 '19 at 07:46
  • Still not any solution? – Sky Oct 15 '20 at 12:50