[MUSIC PLAYING]
JEN PERSON: All right.
You say things, and then I'll--
TODD KERPELMAN: All right.
We'll say things.
JEN PERSON: We'll say thanks.
TODD KERPELMAN: Oh god, we're nerds.
[LAUGHTER]
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 your host, Jen Person.
And today, I'm joined by my co-host, Todd Kerpelman.
Welcome.
TODD KERPELMAN: Hi, everybody.
This is a very special Cloud Firestore
version of "Ask Firebase."
I think all of our questions today
are about Cloud Firestore, so hopefully we
have some answers for you.
It's actually out.
We can talk about it.
JEN PERSON: We can talk about it.
Let's do it.
TODD KERPELMAN: Let's do it.
JEN PERSON: [? Jang-Son ?] Jon, on YouTube, wants to know,
how can I query data from Firebase using a page number
without any last item data?
Is it possible to do that?
TODD KERPELMAN: I think what you're
asking for is basically an offset query,
where you're like hey, let's query
this set of documents from a collection,
but start at number 50.
This is something you can do on the server libraries.
You would just add a dot offset modifier to your query.
But you can't do this on the client libraries.
Turns out, I think, part of the reason
is this has a lot of issues with offline support
and that sort of thing.
But depending on your use case, you can still kind of
jump ahead based on whatever data you're sorting by when
you're running your query.
So if you've got a query or a collection of employees
and you're like, hey, give me all employees sorted
by last name, you can absolutely say, give me
our employees sorted by last name starting with F,
and then you can jump just to that part of your collection.
But you can't say, hey, give me all my employees
starting at employee number 50.
Which, I don't know, I kind of feel
like maybe the starting with F or starting with G thing
is probably better because you actually know what that means.
JEN PERSON: Right.
So probably for most use cases, there
is a possibility to do that.
And then, maybe if not, there are some server options,
as well.
TODD KERPELMAN: Yep.
JEN PERSON: All right.
Javier Ruiz, on Twitter, asks, is there
any way to retrieve subcollections on Firestore?
I want to filter only organizations
where the user is a member.
TODD KERPELMAN: Kind of, not really, but maybe.
Is that good enough for an answer?
JEN PERSON: Oh, that's perfect.
TODD KERPELMAN: Do we need more--
JEN PERSON: Moving on.
TODD KERPELMAN: Next question.
Oh, all right.
I'm being told we need more detail.
So basically, I think what he's asking
is, could you query a document based on items that exist
in that document subcollection?
JEN PERSON: Right.
TODD KERPELMAN: Which is called a collection group query.
Right now, there's no way we can do this.
It's something the team is looking into.
They'd really like to support it.
But right now, any query in Firestore
is just searching for a document within a collection
based on that document's attributes.
Now, you can cheat a little to get what you're asking for.
For instance, let's say you've got a document, or a collection
full of soccer teams.
Each document is one soccer team.
Then it's got a subcollection of team members.
So if you want to look for, say, all
soccer teams that have a player name Jennifer,
you couldn't do that by searching
among all the subcollections, or you can only
do that for one individual team.
JEN PERSON: Right.
TODD KERPELMAN: But what you can do
is, within your original soccer team document,
you could add a Players field, which would be a map.
That's the thing that kind of looks like a dictionary.
And the keys here would be equal to the player name,
and then the values might be, for instance,
an array of the actual document IDs in the subcollection.
And then, basically, Cloud Firestore
does let you query for documents based
on those values of those keys, even if they're
nested inside of a map field.
Two caveats here.
One, this is going to require work
on your part to keep this list in sync
with what's in your subcollections.
And then also, did you know you're
limited to 20,000 fields in a single document in Cloud
Firestore?
JEN PERSON: I did not know that.
TODD KERPELMAN: None of us really ever
run into it very often.
But if you're going to start doing
weird auto-generated stuff like this, yeah,
maybe you've got to watch out for that.
But I think in our example, I don't
know of a soccer team that has 20,000 members in it,
so I think you'll be OK.
JEN PERSON: Sounds good.
In conclusion, yeah, sort of maybe.
TODD KERPELMAN: Yeah, sort of maybe.
JEN PERSON: Thanks so much for coming on and answering
some Cloud Firestore questions, and I'm
sure that there are going to be a lot more questions going
forward.
TODD KERPELMAN: Well, hopefully I'll have some answers.
And if not, I'll fake it.
JEN PERSON: Thanks so much for watching,
and we'll see you on a future episode of "Ask Firebase."
[MUSIC PLAYING]
Nice.
TODD KERPELMAN: Wow.
That was magic.
JEN PERSON: That was magic.
Do you have a hitchhiker's thumb or just a--
TODD KERPELMAN: I do.
Look at that.
JEN PERSON: A little bit, a little bit.
Yeah.
That's pretty substantial.