How to provide predefined data structure to Firebase Database - firebase

I need to put a default structure for some data in Firebase Database.
I'm developing a chat application using Firebase with a static list of chat groups.
There is a way to manually push the list of groups (with all the data fields needed already filled) or some others predefined data without using a mobile app or a website?

You can create the data structure as a JSON file and them import that JSON file into your Firebase Console.
Alternatively you can import the JSON file from a command line, using the Firebase CLI's database:set command.

Related

How do i import data to firebase that is in csv formate?

I have date in form of csv and have to upload to firebase for an application is it possible to connect a csv file to firebase project?
Is it possible to do a bulk insert in firebase insted of manually entering the data?

How to delete a whole file from firebase storage - flutter

This is how my DB looks like:
and I wanna delete everything on that file.
This is what I've tried so far:
FirebaseStorage.instance.ref().child("User ($uid)/ads").delete();
FirebaseStorage.instance.ref().child("User ($uid)/ProfilePic").delete();
the second line deletes the ProfilePic, but the first line returns an error.
I'm new to firebase and flutter so bear with me.
There is no firebase API to delete all the files with a certain prefix i.e. files you see in the console within a certain folder.
One way to achieve this is by using listAll() method to fetch all the files with certain prefix and delete them individually later.
Flutter firebase storage listAll() method is currently available in dev version of package, in version 5.0.0-dev.1, which you can use as shown below:
firebase_storage.ListResult result =
await firebase_storage.FirebaseStorage.instance.ref().listAll();
After using listAll(), you'll get all the files and then you can delete them individually.
Additionally, you can delete files on your backend server also.

Move a single collection in Firebase Cloud Firestore from one project to another

I have to Firebase projects, one is for dev and another is for production. I create a bunch of collections and after they successfully pass the test, I'll need to move them into production database. How can I do this without using Cloud Shell, or are there any alternative suggestions of database?
Thank you!
You can export the collection using cloud shell
Manage export ad import
In case you want to move collections between your dev and your production databases, without using Cloud Shell, there is an alternative that you can follow.
For you to achieve that, you will need to follow the below steps.
Create a Cloud Storage bucket to hold the data from your source project.
Export the data from your source project to the bucket.
Give your destination project permission to read from the bucket.
Import the data from the bucket into your destination project.
With these steps, you should be able to migrate data between your projects and have this way, the structure you want of a Development database and a Production database, where you can easily transfer the data. I would recommend you to check the official documentation Move Data Between Projects, to get the whole tutorial on how to achieve the above steps, in case you have doubts on how to achieve them.
Let me know if the information helped you!

how to add a pushkey when manually entering data via the firebase console?

I would like to create data in a new firebase database and I need to include pushkeys. I know it can import data via a JSON file I do not know how to create a pushkey in a JSON file.
I have tried using the firebase console data entry tool but could not figure out how to do it. Googling the problem did not supply and results.
If anyone can help I would prefer to use the firebase data entry tool.
you can write any key just be sure that your key is not duplicated and upload your JSON file, there is no problem doing that

How to create test users during development with Firebase?

I recently started building my first Firebase app, and I'm unsure how to create test users.
For non-user test data, I can keep a testdata.json file in my codebase and import it via the Firebase Console, but there doesn't seem to be an equivalent mechanism for users.
I'm aware that the latest version of firebase-tools (v3.2.0, released 4 days ago) added an auth:import command, but when I checked the docs, I saw that it expected password hashes to be pre-generated, which is not something I know how or want to do manually.
If there was an equivalent auth:export command that generated a file appropriate for feeding to auth:import, then I could use the Firebase Console to manually create a few users, export them to a file, and check it into my codebase (just like testdata.json), but there is no such command.
Even then, the fact that the Firebase Console doesn't let you set basic profile attributes (like displayName) on users is yet another obstacle...
There are three ways to create email/password users:
through the API
through the Firebase Console
by importing them with the Firebase CLI
For your use-case all three of these sound equally applicable. If you're having trouble getting one working, edit your question to include the minimal steps that reproduce the problem. If you'd like to request a fourth way, I recommend filing a feature request.
For anyone following along with this post, it appears the Firebase CLI added this export feature:
firebase auth:export users.json
However it's not clear to me how user password hashes are preserved for auth:import
The easiest way to add test users with JSON + Firebase console.
Go to your project -> develop -> database
click menu -> export JSON to see your Db structure
add new users (or other data) to this JSON
Go to your project -> develop -> database and delete your database
click menu -> import JSON and paste your new JSON-file
Now your Db contains test users!

Resources