FireStore database is a cloud-hosted, NoSQL database that may store JSON documents. FireStore databases are managed within a FireBase project, thus you have first to create a Firebase project, following next steps.
At the end you will create a simple Dotnet console application to get your JSON documents.
- https://firebase.google.com/
- You should be logged in with a google account.
- Click on “Get started”
- Click on “Create Project”
- Give a name to your project. A unique identifier will be proposed for your project (Remember it! You will need it later to access your project).
- Choose whether you want to track with Google analytics or not. It is your choice.
- Create Project. It will take a while.
- Proceed with continue
- Expand the Build menu and select Firestore Database
- Click on “Create Database”
- Start in production mode
- Set your location
- Wait …
- Start a new Collection
- Give the collection ID “students”
- Select Auto-ID and add two fields for your first document: name and number
- Add a couple of more documents with the same structure: name and number.
- Select Project Settings
- Service and Accounts
- Generate a new private key
- Generate Key
- Download and later copy it to the AppFireStudents project folder.
- Create a dotnet console application to access your fire-students database
- cd AppFireStudents
- Open https://www.nuget.org/
- Type on search: google cloud firestore
- Select Google.Cloud.Firestore by: google-cloud
- Copy .NET CLI command
- Paste
- Type
cat AppFireStudents.csproj
and you will observe:
-
Paste here, in the AppFireStudents folder, the json file downloaded in step 22.
-
Set an environment variable GOOGLE_APPLICATION_CREDENTIALS with the path to the json file, such as (notice in Linux use EXPORT rather than SET):
- Write the following
Program.cs
. NOTICE that you should use your project ID on line 9 where you findFirestoreDb.Create("USE here YOUR Project ID");
(e.g.fire-students
). On step 19 of this guide you may find your Project ID.
- dotnet run should produce something like: