React devs might find this archived course helpful to reference, but this course has been updated! We now recommend you take the Firebase Fundamentals course.
Transcript from the "DocumentSnapshots" Lesson
>> Steve Kinney: So QuerySnapshots hold onto a number of QueryDocumentSnapshots, which inherit from DocumentSnapshot, that's a mouthful. Let's talk about DocumentSnapshots before we go on there, as well. They have an id, that is the individual id of that document, whether or not it exists. Cuz you could theoretically go to a document id that does not exist, in a database, and query for it.
[00:00:22] It'll be empty, that might be useful for making a new document. So when we create new posts, we're gonna be like, hey, just assign me a new id, whatever, just generate one for me. But when we start storing user profiles later, we have a user id, right, we already know the id that we wanna use, right?
[00:00:43] So we might check in that point, to see, hey, do I already have a profile for this user that just logged in? If so, I don't need to make one, right, but if there's not one in there, then I wanna make one, so we'll use exists at one point today, too.
[00:00:56] metadata and ref, remember, we talked about before, ref is the reference to that spot in the database. This is the data, we're looking for the location in the database, if we needed to go back and find that. We'll also be using that towards the end of this workshop, as well.
[00:01:10] The methods are a little bit more important, in this case. data() will get you back all of the fields on the object, .get() will get you back a single field on the object. So if you say, .get first name, you will get the first name property on that object, should it exist, and isEqual() is useful for comparisons.
[00:01:30] All right, so that was our taking our vegetables with QuerySnapshots and DocumentSnapshots. Let's go ahead and play with this a little bit.