0

I have collection of chats and I want to search through this collection by chat's members. Collection looks like:

{
 ...
 owner: 'user-123',
 members: ['user-123', 'user-456'].
 membersData: [{
  id: 'user-123',
  name: 'Jack'
 },
 {
  id: 'user-456',
  name: 'Jane'
 }
 ]
 ...
}

The reason of this that I can't search by members' ids using array-contains if members are objects. Is this solution OK? I have a very small experience in firebase (and noSQL databases generally) so may be there are best practices for this type of tasks?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Oleg
  • 49
  • 1
  • 6
  • You can search by objects but only using all the data. I think that this [article](https://medium.com/firebase-tips-tricks/how-to-update-an-array-of-objects-in-firestore-cdb611a56073) might help. – Alex Mamo Apr 28 '22 at 07:55

1 Answers1

1

Yup, that is completely acceptable an in fact the idiomatic approach if you want to be able to search for just member IDs.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807