Firestore retrieve two collections by references at a time.

Database & APIs

Hi,


I have collections below in the ff:

collection forum_bulletins:

  • id

  • name

  • order

  • List<reference<forums>>

collection forums:

  • id

  • name

  • order

  • reference<forum_bulletins>

And these are used to display on 'drawer' on app in ff format

ForumBulletinA(order:0)

  • ForumA (order:0)

  • ForumB (order:1)

ForumBulletinB(order:1)

  • ForumC (order:0)

  • ForumD (order:1)

ForumBulletinC(order:2)

  • ForumE (order:0)

  • ForumF (order:1)

+ in every forums must have posts.

Assuming examples above, I need to get all of the forum_bulletins and its referable forums in single data retrieval(call).

If it is in code, I could probably achieve this like below:

FirebaseFirestore.instance.collection('forums') .where('forum_bulletin_id', isEqualTo: selectedForumBulletinId) .get() .then((querySnapshot) { querySnapshot.docs.forEach((doc) { print(doc.data()); }); });

But in flutterflow, it seems it only supports 'document from reference' which retrieves a single document in every reference, and I am worried this would cause a lot number of calls to the firestore which is directly related to the costs when the users and the calls gets greater in the future. If I am retrieving data in this way to achieve the form like the example above, it would call 7times (1 for the forum_bulletins and 6 for each Document from Reference)

Does anyone could give me advise so reduce the number of calls to the firestore server?

  • I've tried subcollection but it seems flutterflow content manager do not support subcollection, so I decided to make all of the collections on the top most level of the firestore.

Thank you so much for your guidance in advance!

Have a great day!

What have you tried so far?
  1. Document from reference -> induces so many calls which is not desirable.

  2. Put Json data (forums) under forum_bulletins collections -> no forum id created for posts to get reference.

  3. Get thru 'Query Collection' -> cannot get referred collection documents but only document ids inlcuded on the selected collection. ex. forum_bulltins and forum Ids

  4. collection forum_collections and subcollection forums -> difficult to test the test data due to lack of support on flutterflow firebase content manager.

Did you check FlutterFlow's Documentation for this topic?
Yes