How can I structure data in Firebase database? - android

I need to develop an app for university, but I don't know how to structure my data in Firebase.
In my app there are users who can create events with different questions.
Example: an event poker tournament is created with 2 questions.
1st question: Do you participate?,
2nd question: Have you ever played poker?
When the event is created, users can answer yes or no to each question. The organizer should be shown the number of yes and no answers per question.
Furthermore, the users should be able to see all the answers they have given.
I am new to Firebase and would need your help.
I use the Firestore database and program in Kotlin
Thanks
Augustin

Related

group chat in flutter using firebase with a twist

Disclaimer: I have never worked with firebase or any other DB so my idea is pretty rough and I will be glad if u correct me in some of my assumptions. Also this is my first question on StackOverflow so I hope it will be detailed enough.
I am currently working on my project which is basically a group chat in flutter using firebase, where I should be able to create a new group chat(create a new DB in firestore) trough the app, let other ppl join(assign them to the new group chat DB).
The twist: If I send a message to the group chat I want other ppl to see a pop-up saying: "do you accept this message", no=> doesn't show / yes=> Shows the message but deletes it for others.
This app is nothing but my idea of how to confirm my theory and also learn a little bit more about both flutter and firebase, so please do not mind if it's useful or not.
Assumption: Each groupchat has it's own DB (Can I create a DB in firestore trough app / send request to?)
Question: Can I assign a specific ID to each message and choose and further edit who is going to be able to see the message trough the app(app_instance_1"I accepted the message so only I and sender can see it")?
Here's a great article for making a Flutter chat app: https://medium.com/flutter-community/building-chat-app-in-flutter-with-firebase-888b6222fe20. If you need more detail or help just write a comment.
About your assumption. Each app usually is connected to one database, and within the database, you can have separate documents to hold each group chat. You can also set up documents for each individual user to save the chats that only they can see. Within documents, you add collections that hold your data.

Creating groups with Firebase Realtime Database in Android app

I have an Android app that uses the Firebase Realtime Database. At the moment it is a single user app, in that when a user logs in, using Firebase Auth, the data they create is kept private to them. What I need to do for the next phase of the project is to allow for the creation of teams or user-groups that have access (read and write) to the data currently created by a single user.
The database structure and rules for doing this are understood, however, the issue I have is how to create the groups.
I did find the following blog and it is very close to what I need, it does not make clear how a new user would create the pending membership entry in a specific "chat" (this is a group chat sample).
https://firebase.googleblog.com/2016/10/group-security-in-firebase-database.html
Any points on resolving this final issue would be much appreciated.
Sid
Just simply create groups like below
|--Groups
|---group1
|-----uID1 - owner
|-----uID2 - participant
|-----uID3 - participant
..............
follow this https://firebase.googleblog.com/2016/10/group-security-in-firebase-database.html link. There are example groups and rules. It will help for u to proceeds it.
Follow this https://firebase.google.com/docs/database/ios/structure-data to make good structure of data to increase performance

ANDROID FIRESTORE : get all the documents that has "current user" in it's sub collection [duplicate]

This question already has an answer here:
How to query a Firestore collection using a property from a step deeper with Kotlin? [duplicate]
(1 answer)
Closed 4 years ago.
I am new to Firestore cloud and I am trying to learn about it.
I am trying to build a project and I am stuck at one point.
My Firestore database looks like this:
enter image description here
enter image description here
I have a Groups collection that has "Users List" Sub-collection" where I have "timestamp" and "user_id".
When I created a group I grabbed the user_id of the "user" that creates a group and added that in "Users List".
Now I am looking to retrieve all the "Groups"(groupName) that the "CurrentUser" is involved in, and I am having hard time to figure it out because I found that NoSQL databases are very different from SQL databases.
Would be great if someone can shed a light on this matter.
Thank you
I'm not sure about this, but I think your best bet is to add some field to collect group that each user involve in "Users" Collection using array or object to collect it since Firestore can collect array or object.
But TBH, I not sure this is the best, but it is the best I can think rightnow. Because with these you only need to query 1 time for each user that you want to get usergroup and it help you to not use lots of query to get usergroups for each user. But it will couse you some additional size. But it still fine since Firestore costing is base on both query and size for this case. Little(?) additional data is better than waste lots of query to get usergroup for only one user.

Firestore clients and invoices, amended requirement

This question is a follow up question to the one posted here:
Firestore: Clients and invoices, how to model it
I am trying to understand the thought process behind modelling evolving requirements in Firebase/Firestore.
Assuming the accepted answer was used for the model, then 2 months you get a new requirement after the app has been released. Now the requirement says:
We need to get the invoice detail (not only id but the full details) for user whose last name is xyz.
How can model this assuming the database/app has been live for 2 months (so there is data in there already). The last name is already an attribute of the user details.
Thank you
According to the requirements that we see in this post, which I understand are mandatory in your project:
Show invoices that a client has
and
Update all invoices in the system to false
The most appropriate schema that can I recommend you, is the one in which you should add a new property called userId, beneath each invoice object.
So please consider using this tehnique, which is actually called a the reverse lookup. It will help you query your database more easily and will also help you solve both problems.

How to match elements from one set to elements in another set using Firebase?

I recently started to learn Android and I came across a problem. I want to create a code for Firebase (the database I am using to store values) such that the contents from one set are matched to elements in another set.
The scenario is as follows: there is a student who wants to learn or is interested in learning a new skill (C/C++, drawing, music, etc.), if he were to update them in their profile, he should get suggestions as names of other users registered in the application who have already listed their skill set.
It is much like how Facebook suggests common friends, but here, the basis for suggestion is what skills the user has and what he wants to learn.
I worked on the same thing for one of my apps. I'll write about what I did to achieve that
First of all, you need to design your Realtime Database structure in a way to achieve that.
Example of a Individual User node in your database at firebase could be like
User
- Personal Details
- First name
- last name
- Dob
- Interests (values like "music,movies,sports") //Separated by a comma
- ...
Now lets say User A likes "music" and that you need to suggest him other users who likes music too, In this case what you can do is retrieve all the users who have interests "music" in their profile.
reference.addChildEventListener()
In here,inside the onChildAdded() you can compare to see if the Interest of a particular user has music in it. (if it does, add that user to your arraylist for your recyclerview to display it.)
Hope it helps!

Categories

Resources