Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multi environment DB's with Firestore

I've been looking at how to create multiple Firestore instances in Firebase, I need different Db's for prod, staging and development. I read the documentation and seems that I only need to modify the "Google-services.json" file in the applications. what I don't get is what should I modify and how that would look in the console.

  • Am I going to see different instances in the same project?

  • I need to create different projects for every environment and modify those values in the file?

  • If I need to test something that requires testing in all environments and all of them require Blaze to run that test do I have to pay Triple?

Thanks in advance

like image 678
Dyan Avatar asked Feb 06 '18 17:02

Dyan


People also ask

How many collections can firestore create?

The limit is that you can only go 100 subcollections deep, which is very large and you should never reach that point unless you have the most detailed and specific app in the world. So to summarize, there are no limits on how many collections you have, just how deep you can go within a collection.


2 Answers

Firebase doesn't support the use of multiple Firestore instances in a single project.

The Firebase team strongly recommends creating different projects for each of your environments to keep them separate. This probably means you will have to build different apps that each point to different instances, or you will have to somehow configure your app at runtime to select which project you want to work with.

There is no obligation to add billing to any of the projects you don't want to pay for, as long as you accept the limitations of the Spark plan.

like image 172
Doug Stevenson Avatar answered Oct 08 '22 14:10

Doug Stevenson


Yes Firebase doesn't support multiple instance in a single project. However my case, i created 3 different document in Firestore root and setup each environment to refer these documents accordingly. Each document will have the same collections, sub collections and documents.

For example,

dev -> users -> details
    -> others_collection -> details

stag -> users
     -> others_collection -> details

prod -> users
     -> others_collection -> details

On the client side, each environment will get the collection like this :

db.collection(`${env}/users`)

I am doing this on small project and seem pretty happy with what Firestore provided. In single project. i can create many ios/android apps according to the environment and each environment have it own document and collections in Firestore.

like image 26
zzas11 Avatar answered Oct 08 '22 15:10

zzas11