0

I've been working on a small messaging app in Flutter. So far I've got it working with as a giant group message, but I'm trying to move it over to peer-to-peer messaging. My code for this: stream: _firestore.collection('Messages').orderBy('TimeSent').snapshots(),

I have a collections called Convos that holds an array of document IDs. Those document IDs reference a 2nd collection called Messages. I want to be able to take the array of document IDs from Convos and search the 2nd collection.

Basically what I'm trying to do is create a Flutter app that gets all the messages related to a conversation from a mass list of messages. This way you can have multiple conversations each with multiple different messages.

I tried using .where() but was unsure how to use it to search the document ID of a message

Another idea I came across was to create multiple streams for each document ID in Convos message list, but this seems like a bad idea and very hard to achieve.

Can anyone lend a little help?

Joesobo
  • 25
  • 1
  • 1
  • 4
  • You're going to have to write code to perform additional queries. Firestore does not offer a "join" type query that takes the results from one query and applies that to a second query. – Doug Stevenson Jan 18 '20 at 22:42
  • 1
    In general you can just load each individual document. The performance of that is (on a reasonable set of documents) not as bad as most developers think. Alternatively, you can use a server-side solution, where this operation exists, or retrieve batches of documents with the (relatively new) `IN` operator. See https://stackoverflow.com/questions/46721517/google-firestore-how-to-get-document-by-multiple-ids-in-one-round-trip – Frank van Puffelen Jan 19 '20 at 01:05

0 Answers0