Top questions from Stack Overflow and Twitter with Frank van Puffelen, Part II - #AskFirebase
Why Stack Overflow recommends it
Stack Overflow users link it when explaining how to model Firebase data with unique values as keys, how security rules cannot search values, and why fetching items one at a time is not slow.
Recommended by 3 people across 4 different months, 2016 to 2019.
What it is
An episode of the official Firebase #AskFirebase series in which Frank van Puffelen answers popular Stack Overflow and Twitter questions about the Firebase Realtime Database. Topics include concurrent read/write limits, snapshot ordering, wildcards in security rules, and checking unique child values.
What people said
Recommends Frank van Puffelen · 2016-03 · Stack Overflow · on “Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly”
Update: we now also cover this question in an AskFirebase episode [this video] . Loading many items from Firebase doesn't have to be slow, since you can pipeline the requests. But your code is making this impossible, which indeed will lead to suboptimal performance. In your code, you request an item from the server, wait for that item to return and then load the next one. In a simplified sequence diagram that looks like: Your app Firebase Database -- request item 1 --> S L e o r a v d e i <- return item 1 -- r n g -- request item 2 --> S L e o r a v d e i r n <- return item 2 -- g -- request item 3 --> . . . -- request item 30--> S L e o r a v d e i r n g <- return item 30 -- In this scenario you
Recommends Frank van Puffelen · 2017-03 · Stack Overflow · on “Firebase authentication rule checks email”
In the JSON you shared there is no path /users/email . So this rule will never be true : root.child('users/email').val() === auth.token.email You cannot in security rules search under a path for a specific value . You can check for the existence of a specific key though. See Firebase security rules to check unique value of a child #AskFirebase [LINK] , Firebase android : make username unique [LINK] or my answer in this #AskFirebase video: [this video] .
Recommends Frank van Puffelen · 2017-03 · Stack Overflow · on “Firebase authentication rule checks email”
In the JSON you shared there is no path `/users/email`, so that rule will never be `true`. If you're looking to register unique email addresses, you should keep them as the key - not the value. See [LINK] [LINK] or my answer in this #AskFirebase video: [this video]
Recommends Alex Mamo · 2017-05 · Stack Overflow · on “Avoiding duplicate usernames in Firebase Database + Java”
Basically, the userName or the email address should be the name of your node. Regarding rules, you can use wildcards. If you create a userName George, to verify if exists you only need to put a reference on users node and use exists() method. Please take a look at Frank van Puffelen's explanation from this video [this video] . Even if you'll need to remodel a bit your database, remember that this is the best practice when we are talking about duplicates.
Recommends Sean O · 2019-09 · Stack Overflow · on “How to check if username exists in my firebase database already?”
Yes, I seen the link he posted. Took me a while to understand it haha. Eventually I saw the video [this video] which explains that you need the username to be a key and not a value. Alex Mamo's post was confusing because of the two similar key and value names. Thanks anyway @Teempy!
Cites Frank van Puffelen · 2017-02 · Stack Overflow · on “Firebase multiple where clauses using equalsTo”
When you call orderBy... or other methods, it returns a new query. So you're now creating a new query for each uid that you then don't use. To keep it, you'd need newUidsQuery = newUidsQuery.equalTo(uid) . But that won't solve the problem yet, because a query can only order/filter on a single property and value. See Query based on multiple where clauses in firebase [LINK] . Better news is that this doesn't matter much here, since you can just retrieve the items one at a time. Unlike what you might expect, that's not significantly slower than retrieving them in one go. See Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly [LINK] or
Cites Frank van Puffelen · 2017-03 · Stack Overflow · on “Swift 3 + Firebase: Check if value inside array exists?”
Firebase does not have an ability to check if a specific value exists. If you need this, it typically means you should invert the `users_liked` and use the UID as the key. See [this video] and [LINK]
Cites Jason Berryman · 2018-02 · Stack Overflow · on “firestore - javascript web application requests”
I believe that Frank's answer (also featured on #AskFirebase [this video] relates to the Firebase RTDB, not Cloud Firestore. Cloud Firestore _might_ respond differently.