This question already has an answer here:
How to create auto incremented key in Firebase?
(1 answer)
Closed 2 months ago.
How can I get next key value (User03) continue from last recent key (User02) like image below:
To know the next key in this sequence, you will need to first load all the current keys.
This is one of the many reasons Firebase recommends against using arrays, since such an operation doesn't scale well, and will only work while the user is connected to the database. I recommend reading best practices for arrays in Firebase and what are Firebase push IDs.
Related
This question already has an answer here:
If one of the object to be written has the same content as the one in Firestore, what will happen?
(1 answer)
Closed last year.
Data in Firestore:
Now suppose if I perform a write operation without updating any data, will it increment the write count in Firestore?
I just ran a quick test writing the same value to the same document at an interval, and the usage panel in the Firebase console showed an increase in writes for each write call.
This question already has answers here:
Firestore - get specific fields from document
(4 answers)
How to access a specific field from Cloud FireStore Firebase in Swift
(5 answers)
How to get a list of document IDs in a collection Cloud Firestore?
(4 answers)
Closed 1 year ago.
Suppose I wanted to use Google Firebase's Firestore as the backend of a simple website showing a list of (journal) entries, and the ability to view an entry, edit an entry, and delete an entry. Fundamentally, I would want to retrieve the list of entry titles, so I could present in my website a table of contents. Then when the visitor clicks one of the titles, the website would navigate to the entry's content.
Now, my question is, how do I get just the titles without the content, of the entries? As far as I have read, this is not possible. I present this problem here to confirm whether I have missed something, or if it is indeed impossible with Firebase to get some of the data from a collection of records, without having to retrieve all of the data.
how do I get just the titles without the content, of the entries?
As you've already found, the client-side SDKs for Firestore always retrieve full documents. The server-side SDKs and REST API have a projection/selection mechanism to retrieve only a subset of the fields, but that ability does not exist in the client-side SDKs.
This question already has answers here:
Firebase android : make username unique
(4 answers)
Closed 2 years ago.
In my app, user should be able to connect with each other. So to identify each other, they should have some human readable property, which they can share easily. I was wondering if there is any way that, I could have a Human readable "username" similar to Uid?
I was initially planning to save an Email-id of the user in the database, but as it can change, this approach is not recommended. Also, this approach will fail if user logs in using their phone number.
So, is there any in-built Firebase mechanism to this? What are the best practices / design patterns here? What is the commonly used approach in Firebase world, when it comes to 'identifying each other' or 'sharing'?
It's similar to my answer here.
You need to keep a separate node in firebase realtime database regarding that.
So if your user tries to connect with any other user name user123, you will need to find the node user123 in database and read the UID which will be stored inside and then proceed to your further actions.
Alternatively to make it less lengthy, you could use usernames instead of UID, so there is no question of UID in the application but you will need to take care there are no same usernames and could increase complications.
I'll prefer the first method. Do let me know if you need more assitance.
This question already has answers here:
Document Updates - Do updates with no changes still cost 1 write?
(2 answers)
Closed 2 years ago.
Im trying to find out how firebase is billing write operations. In the billings documentation I could not find a clear definition of when a write is counted. Lets say I run a set query with the exact same data of the original documen, such that the document won't be affected, will this be billed as a write operation?
When I run my query with the console open nothing happens, and i was just wondering if these writes do also count.
When you write data, the server doesn't check if the data you write is the same as what already exist. Instead: it writes the data you provide. Hence: writing the same data is still counted as a write operation.
I find it easiest to understand the billing for Firestore by thinking of it as reads from/writes to a disk. When you tell a disk to write a file, it writes that file.
This question already has an answer here:
firebase equivalent to sql where in ()
(1 answer)
Closed 5 years ago.
I use orderByKey for requesting data by keys from Firebase. I can get several objects if keys are similar — start or end with the same string.
But how can I retrieve totally different keys with one request to Firebase, e.g. "n:1-2-3" and "n:2-3-4"? I use equalTo, but can I specify more than one key there?
I know how to do it with different requests — one request per one key, but it's not optimal.
Currently firebase only supports one condition. Explained more in the below text:-
If lets say you have two keys that are a123 and a234 then to retrieve you can do this:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference();
ref.orderByKey().startAt("a").limitToLast(10).addValueEventListener(..){..}
The limitToLast() method is used to set a maximum number of children to be synced for a given callback
You can use limittolast or limittofirst, to limit the results that are obtained from the database.
Also currently firebase only supports one condition. So you cannot have more than one orderbykey or orderbychild or the two together..