Check out a free preview of the full Firebase with React, v2 course:
The "Collections Introduction" Lesson is part of the full, Firebase with React, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Steve gives an introduction on how to query data from the Cloud Firestore.

Get Unlimited Access Now

Transcript from the "Collections Introduction" Lesson

[00:00:00]
>> Steve Kinney: So let's talk about a little bit how we work with Cloud Firestore before we start writing some code. So we're gonna create a Firestore object when we start writing our React code, and there's kind of a root. You can't put anything in the root, but you can have many collections, right?

[00:00:18] In this case we'll have a post collection. Right, and this will be a series of posts. Now, that collection will have a bunch of documents, you can go ahead and get a particular document out of there as well, right? So here we have a collection of posts, we can go get a document out of there and that is a single post document.

[00:00:38] However, a document could have, in this case a post, could have many comments, right? So we could have a sub-collection of comments that we can pull from as well. So you can kinda see it. There's this back and forth between collections and documents, collections and documents as we go through.

[00:00:55] We have a collection, we can get a specific, we can get all the documents in a collection or we can get a specific document out of a collection. And then that document could have a sub-collection. In this case, it's comments. Could be anything, though, right? You could have books and then chapters, or books and then characters, or both in there, and kind of query down as you need to.

[00:01:16]
>> Steve Kinney: And then we can go get a specific comment as well. Right? So you can see, it oscillates back and forth between a collection, a document, a collection, and a document. If you don't want to keep typing all those methods, you can use something very similar to a path or a URL.

[00:01:32] But it's the same basic idea, right? That these are the same concept, right? Which is there is a collection, there is a document, there is a collection, there is a document. And that's kind of how we traverse up and down Cloud Firestore. For whatever level you get to, it is shallow, there.

[00:01:47] If you just go to get the post, you're not gonna get all of the posts and all of the comments. You're just going to get all of the posts. If you say. I just want a specific post, you're not going to get any of the comments unless you say /comments as well.

[00:02:00] All right? So you get to choose how deep you wanna go.