JEN PERSON: You'll be doing a firecast,
and you'll be like, why did we name that parameter, like, six
words squished together?
And now I have to keep saying it.
[MUSIC PLAYING]
CREW: Take one, [INAUDIBLE].
[CLAPPERBOARD CLICKS]
JEN PERSON: Hey, all you Firebase developers.
Welcome to another episode of "Ask Firebase,"
the show where we answer your burning Firebase questions.
I'm Jen Person, host of the show.
And today I'm joined by my co-host, Rachel Saunders.
RACHEL SAUNDERS: Hey.
JEN PERSON: Welcome to the show.
RACHEL SAUNDERS: Oh, thank you.
JEN PERSON: So what do you do for Firebase?
RACHEL SAUNDERS: Well, I'm actually new to Firebase
and I am--
JEN PERSON: Welcome.
RACHEL SAUNDERS: Thank you.
And I'm a technical writer.
So whenever there's a new product or a new feature,
I learn about that feature, and I run the workflows,
and I make sure everything kind of fits
OK with what to do with that feature.
And I write about it so that all of you guys
can actually use it.
JEN PERSON: Yeah, it's such an important role to Firebase,
because if you just have this product sitting
there but no description of what it does or how to use it,
it's useless.
And I know you already work on our [? one ?] resource
to make them, to be helpful to our developers.
Let's do another one.
Let's answer some questions about Firebase.
RACHEL SAUNDERS: Yeah, definitely.
JEN PERSON: This question comes to us
from Wender Patrick, who wants to know,
using the restaurants review example,
can I use cloud functions to automatically denormalize
this data when there's an update to some user?
What this user is referring to is a video that Todd made
on Cloud Firestore, which we'll link below,
that's talking about collections of restaurants and reviews.
So he wants to know, can we use denormalization for that?
RACHEL SAUNDERS: Yeah, definitely.
And he's specifically asking about Cloud Functions.
Can I use a Cloud Function for that?
And you definitely can.
You can write a Cloud Function that's
triggered by a change in your Cloud Firestore
like in your example--
a user makes an update in their user name.
When that update is made, it triggers a Cloud Function,
and it updates in all of their reviews
and across the database.
So your Cloud Function will access and perform
these update actions in the Cloud Firestore
through the Firebase Admin SDK.
JEN PERSON: Mhm.
RACHEL SAUNDERS: So you'll need to install
a couple of packages, and then before you
write your Cloud Function.
JEN PERSON: Yeah, and so fortunately we
have a Codelab that shows how to do this, right?
RACHEL SAUNDERS: Yes.
Mhm.
JEN PERSON: So we'll link to that below,
where you can see a specific example of using Cloud
Functions to denormalize data.
So when you make an update in one place,
the Cloud Function can handle doing
that update everywhere else.
RACHEL SAUNDERS: Yeah, it's really handy.
JEN PERSON: Our next question comes from Henry.
Thank you so much for all of your questions.
You're always asking us great questions.
Should chat messages be appended to an array
or as individual documents in a subcollection in Firestore.
RACHEL SAUNDERS: So this depends on the needs of your app,
but generally it's better to store
as documents and a collection rather than as an array.
It's just easier to determine if a given value exists,
and it's easier to make changes.
And then once you have your data structure,
you can easily make that subcollection of documents
into an array, but client-side.
JEN PERSON: Right, I agree.
So you can definitely do it either way.
And it's true that there may be situations where it makes
more sense to use an array.
But in general, I just think documents are better,
because going forward, thinking about what your app might need,
it's great to be able to know that you can query by any
of the fields you put in there.
It's going to be easier to add fields to your documents.
And you had brought up earlier today
that you can now query arrays to look for something that exists
in it, which is a great step.
But you can still-- you just have more power with documents
than with arrays.
RACHEL SAUNDERS: Yeah.
JEN PERSON: So that's my opinion, though.
Keep that in mind, right?
OK.
This one's-- yes, this one's also for me.
RACHEL SAUNDERS: So the next person asks,
is there a way to update security rules
for real-time database or for Cloud Firestore from Cloud
Functions?
So again, another Cloud Functions
related to the different services we have.
Imagine I have multiple message boards, dynamically created,
and I want only some members to have write access?
JEN PERSON: That's a great question.
And the short answer is no.
But it is certainly possible to restrict things dynamically.
So one way you could handle this is by having, let's say,
a collection of documents where it basically
just says permissions.
So maybe the document ID could be that user's GUID.
And then it sort of lists what permissions they have.
So message board one, true, message board three, true.
Under each user, it would say what they're allowed to access.
Then in your rules you would basically
have a section that's like, let's say,
a document that's a collection message boards and then message
board ID.
And then you could restrict based
on whether someone has that specific value in their options
for what I'm allowed to access.
And that was a lot of words I just said.
So I think this calls for another example.
And this is actually something I'm
going to be talking about in a Firecast.
So if that's out now, I will link to it.
Otherwise, stay tuned, because it's going to come out.
I'm going to talk about how you can handle
these sort of permissions.
So while you can't dynamically create new rules,
theoretically the rules don't really change in this case,
because you want to restrict access
so that only specific users can reach certain message boards.
So you can do that by saying, look up,
are they on this list of people that
are allowed to access them?
You also have the option to use custom off claims.
But because you are limited in how many claims
you can put on a specific user, I
would only recommend that if you have a couple different types
of data permissions.
So if you need to be able to have people have
unlimited different combinations of message boards
that they can be a part of, then that
wouldn't be the best option.
If you're not familiar with custom claims,
I'll link to that too.
[MUSIC PLAYING]
So is there a specific error that you
see people commonly make in their writing that
just drives you crazy?
RACHEL SAUNDERS: In they're writing,
like from the original source material, from our [INAUDIBLE]
and things like that?
JEN PERSON: Maybe.
RACHEL SAUNDERS: Sometimes they make it a little bit
difficult to like run the workflow.
They leave out an important step.
They just kind of do it themselves
and so they don't even write it down.
And so it's a missing piece of the workflow.
And so for especially beginner users,
it's sometimes-- every single step
needs to be laid out really clearly,
so making sure that we run the workflow and kind of document,
truly document, what the workflow is
is really handy, really important for our developers.
JEN PERSON: Yeah, definitely.
That's so true.
We're so close to the products that we work with that it is
really easy to just get so used to doing things a certain way
that you don't--
you lose that first experience.
RACHEL SAUNDERS: Right.
JEN PERSON: What's that like from being the original user.
RACHEL SAUNDERS: Yeah, definitely.
Yeah, our beginners are--
just anyone who's not familiar, even to just a new service
that Firebase offers, sometimes they
need to make sure that they're kind of like--
don't assume that they've used all
the other Firebase services, which you should,
but you know they don't always have everything set up,
and so you don't want to make assumptions about anyone
out there.
JEN PERSON: Good point.
All right.
Thank you so much for coming on the show, Rachel,
and helping me answer these questions.
RACHEL SAUNDERS: Oh, it was great.
It's always nice to be able to see
how all these different pieces fit together.
JEN PERSON: Yeah.
Yeah.
RACHEL SAUNDERS: Thanks for having me.
JEN PERSON: And I always learn so much
from people's questions.
These are things that I don't necessarily
think of until someone asks.
RACHEL SAUNDERS: Yeah.
JEN PERSON: So thank all of you who
submitted questions and continue to submit questions.
And when you come across something, and you think
it might be a good fit for the show,
be sure to hit it with #AskFirebase.
And who knows, maybe you'll see it here on a future episode.
And if you enjoy this video, be sure to subscribe
to the Firebase YouTube channel, so you
can check out all of the content that comes out.
Thanks so much for watching, and we'll
see you on a future episode.
RACHEL SAUNDERS: I was first worried
that I would clash with the color scheme,
so I made sure to pick a non [? color on here. ?]
It's very modern isn't it with the [INAUDIBLE]
lines and everything?