Skip to content Skip to sidebar Skip to footer

How To Properly Structure Localized Content In Cloud Firestore?

I'm thinking about migrating to Cloud Firestore from realtime ratabase and wondering how I can properly setup the datastructure for my localized content. This is how it was structu

Solution 1:

There is a simple way for structuring such data in Cloud Firestore. So a possible schema might be:

Firestore-root
   |
   --- articles (collection)
        |
        --- articleId (document)
        |     |
        |     --- language: "en-US"
        |     |
        |     --- //other article properties
        |
        --- articleId (document)
              |
              --- language: "de-DE"
              |
              --- //other article properties

Using this database schema, in Android, you can simply:

  • Get all articles regardless of the language using just a CollectionReference:

    FirebaseFirestorerootRef= FirebaseFirestore.getInstance();
    CollectionReferencearticlesRef= rootRef.collection("articles");
    articlesRef.get().addOnCompleteListener(/* ... */);
    
  • Get all articles that correpond to a single language using a Query:

    FirebaseFirestorerootRef= FirebaseFirestore.getInstance();
    Queryquery= rootRef.collection("articles").whereEqualTo("language", "en-US");
    query.get().addOnCompleteListener(/* ... */);
    

Post a Comment for "How To Properly Structure Localized Content In Cloud Firestore?"