Android

Firestore Tutorial Part 18 – SUBCOLLECTIONS AND CONSIDERATIONS – Android Studio Tutorial

In part 18 of the Firestore tutorial, we will learn how to add sub-collections to a Firestore document and how to query these sub-collections. For this we simply add another .collection call on a DocumentReference, which creates a CollectionReference to it’s sub-collection. We give this sub-collection a name (collectionPath) and can continue this chain up to 100 levels deep. Like on a top-level collection, we can then add documents to this collection or retrieve the existing documents. Subcollections can also be added directly over the Firebase Console.

We will also talk about considerations you have to make when you plan the structure of your database, and when it’s better to use nested objects or arrays rather than subcollections.
Every Firestore query runs against a single collection, so we can’t query across subcollections. We can also not retrieve a document by a value in any of it’s subcollection’s documents and when we delete a document, it’s subcollections don’t automatically get deleted as well, which can lead to orphaned collections that still take up space in the database. Since Firestore bills per number of read, write and delete operations on a document, it can make sense to put related data into an array or nested object.
Documents on the other hand have 1mb size and 20k field limits and only support approx. 1 write per second. Documents can also not be retrieved partially, which can lead to security issues and use up a lot of network data if they are very big.
But since Firestore queries are shallow, we can retrieve a document without automatically downloading it’s subcollections or any of the documents in them, and we can easily paginate documents from a subcollection and set up different security rules for them.
Those are factors you have to keep in mind when we build your app.

Watch the whole playlist:

Code for this part:
https://gist.github.com/codinginflow/826bb69c41c23d664bb48b79aa5fc74c

Firebase explainer video about collections, subcollections and nested data:

____________________
💻 Find the BEST programming tutorials on TutHub:
https://tuthub.io

⭐ Get my MVVM Caching Course now:
https://codinginflow.com/caching

❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflo…

📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter

❓ Join our free developer community:
https://discord.gg/TSnMvmc

📣 Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
TikTok: https://www.tiktok.com/@codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow

💰 Business requests, sponsoring, etc.: info@codinginflow.com

Views :39892
android studio

Source by Coding in Flow

Mourad ELGORMA

Fondateur de summarynetworks, passionné des nouvelles technologies et des métiers de Réseautique , Master en réseaux et système de télécommunications. ,j’ai affaire à Pascal, Delphi, Java, MATLAB, php …Connaissance du protocole TCP / IP, des applications Ethernet, des WLAN …Planification, installation et dépannage de problèmes de réseau informatique……Installez, configurez et dépannez les périphériques Cisco IOS. Surveillez les performances du réseau et isolez les défaillances du réseau. VLANs, protocoles de routage (RIPv2, EIGRP, OSPF.)…..Manipuler des systèmes embarqués (matériel et logiciel ex: Beaglebone Black)…Linux (Ubuntu, kali, serveur Mandriva Fedora, …). Microsoft (Windows, Windows Server 2003). ……Paquet tracer, GNS3, VMware Workstation, Virtual Box, Filezilla (client / serveur), EasyPhp, serveur Wamp,Le système de gestion WORDPRESS………Installation des caméras de surveillance ( technologie hikvision DVR………..). ,

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *