Database
Firestore 🔥
If you haven't already create a firebase project: https://firebase.google.com/docs/firestore/quickstart.
Add Firestore database, to your project in Firebase
In Firebase side panel, navigate to:
Project Overview -> Project Settings -> Service Accounts -> Generate new private keyto generate service account json file, which contains private key. You can also visit this URL:https://console.firebase.google.com/u/0/project/{project-id}/settings/serviceaccounts/adminsdkbut replace the{project-id}with your project.
Set following
.envvariables:AUTH_FIREBASE_PROJECT_ID- id of your firebase projectAUTH_FIREBASE_CLIENT_EMAIL- service account email (get it from step 3 json file)AUTH_FIREBASE_PRIVATE_KEY- private key (get it from step 3 json file)Now your Firestore is setup :)
MongoDB 🧩
Create MongoDB account and cluster if you haven't already: https://account.mongodb.com/account/register
Now we need to create an extra user which will be only used by our app. It needs to have read/write access. In side panel, go to
Security -> Database Access -> Add new Database user
Now we need to get "connection string" URI. In side panel, go to
Deployment -> Database -> Connect. After modal opens, selectDriversand at the bottom you will see connection string looking likemongodb+srv://<db_username>:<db_password>@...
Set following
.envvariables:MONGO_DB_URI- connection string from step 3 Note: Make sure that after first/in connection string, you write the DB name which you want to use (otherwise by default it'stest). Example of connection string:mongodb+srv://{username}:{password}.../dbNameNow your MongoDB is setup :)
Configuration
Database adapter is controlled through the appConfig.tsfile.
database: {
provider: DatabaseType.FIRESTORE // or DatabaseType.MONGODB
}Each adapter has it's own set of required environment variables, together with it's own implementation of common functions to interact with the database.
Adapters don't implement actual business logic. Business logic is handled in the database/index.tsfile together with "collection names".
Collection names are names of tables/collections in the database.
Last updated