How to retrieve child nodes data and update values in firebase:
As I want to make an API in which I create parameters to pass values by it.
Like example I have one node in firebase name as users and under it has user amount is 10. I want to get that data of amount from users node and add some value with it like 10+5 will update in database as 15 in my firebase.
I tried to retrieve data from firebase by seeing youtube, but I'm unable to get what I want; I was only able to get the whole users node data at whole.
That sounds like a 2-step process:
Store the value as a number rather than as a string like you now have it.
Then use the atomic increment operation to increment it by 5.
I want to add a "Notify me" function in my flutter app where the user enters a date and other values so when a document is created with those values, the user can get a notification. I'm unable to add any conditions in fcm.subscribeToTopic();.TIA.
You can create a cloud function and deploy it to firebase Functions, and in that function specify the path of collection (in which your document is creating) and it will trigger when a new document is created (write function for that. example ). in order to send notifications to that user store that user's device Token. you can find cloud Firestore Functions here.
some articles that help: firebase tiggers
Subscriptions to a topic are unconditional. The simplest way I can think of to implement this use-case is to create topics that contain the specific conditions that you are interested in, like date_20210823_value_yourvalue.
Hello guys , how can i get all information inside this Document with using the field [ ID ] , i tried to use the where Query but i couldn't success with that
I assume you wanna do this on the firebase website. Let me show you how I did this using my collection.
Step 1: Go to Filter by field, then select the field you want
Step 2: Add condition which should be "(==) equal to"
Step 3: Click on Apply
Voila! Now you can retrieve a document using a specific field in firestore.
Anyhow, if you want to retrieve a document using a specific field inside a frontend code. Then it would be a bit different depending on the language or framework you use.
I'm trying to make chat app in flutter using firebase. And i want to know, can i make chat using users id? I mean chatID=user1ID+user2ID, is it possible?
I think you can add a field of type array to your chat document and name it as chat _user and just pass the two users ids to it as like this =>
I have a question regarding authentication using Google Firebase.
For an app, I want to build an authentication similar to the one Slack uses: first, the user provides the input as to which group they want to log in to. If there exists a group with the same name as provided in the input, the user is then taken to a login/signup screen.
I've thought about storing users in the realtime database as follows, but I think there must be a better way to do this (since I don't think I can use the firebase authentication in this case):
groups: {
"some_group_name": {
"users": [
"user1": {
.. user 1 information
},
"user2": {
.. user 2 information
}
],
"group_details": {
"name": ..,
"someGroupDetail": ..
}
},
"some_other_group_name": {
...
}
}
I haven't realized if there is an obvious answer yet, so I'm open to suggestions. How would you suggest I tackle this?
Thanks
PS: I'm building the application using Nativescript and Angular, and (so far) there is no server or database involved other than Firebase.
Another suggestion that might work, is by using Firebase Auth Custom Claims. That way, you only need to store the group ID and group name in your realtime database, without worrying to keep changing the database each time user is added or removed.
This is one way you can do it:
Store database exactly like you have it, with it's group ID and name.
In your backend script (I recommend Cloud Function), each time a User is registering themselves, add custom claims in your user: Specifying what group is the User belong to.
Every time user authenticate, retrieve the group ID from custom claims. And there you get it!
Note: be careful not to put too much information in your custom claims as it cannot exceed 1000 bytes.
Read more about it here: https://firebase.google.com/docs/auth/admin/custom-claims
I would suggest you to implement Root-level collections.
Which is to create collections at the root level of your database to organize disparate data sets(as shown in the image below).
Advantages: As your lists grow, the size of the parent document doesn't change. You also get full query capabilities on
subcollections.
Possible use case: In the same chat app, for example, you
might create collections of users or messages within chat room
documents
Based on the reference from the firebase cloud firestore
Choose a data structure tutorial (I know you are using Realtime database but structuring the database is the same since both are using the NoSQL Schema)
For your case:
Make 2 Collections: Users, Groups
Users: User info is stored in the form of document
Groups: In the Groups Collection, here comes the tricky part, you can either store all groups subcollection under 1 document or split into multiple documents (based on your preference)
In the group-subcollection, you can now store your group info as well as the user assigned where you can store user assigned in the form of array, therefore whenever a user access the group, query the user assigned first, if yes, then allow (assuming users can view all group)
You do the thinking now