Firebase with React, v2 Firebase with React, v2

Creating a Firestore Database

Check out a free preview of the full Firebase with React, v2 course:
The "Creating a Firestore Database" 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 sets up a new Cloud Firestore database, then wires it into the application.

Get Unlimited Access Now

Transcript from the "Creating a Firestore Database" Lesson

[00:00:00]
>> Steve Kinney: What we'll do real quick is we need to go ahead and turn on our database. So we'll go back to the Firebase console, and we'll go to Database. And this is kinda what I said before, Cloud Firestore is definitely in beta. But if you look at the screen right now, what is Google trying to push on you?

[00:00:24]
>> Steve Kinney: They have strong opinions on what database you ought to use. If you scroll down,
>> Steve Kinney: [LAUGH] Or alternatively, choose the real time database, right. But they definitely have tried to sell you on the Cloud Firestore first and foremost. And so that's what we're going to go with today.

[00:00:45] So we'll go ahead and we'll create database. And we have two choices, the responsible choice and the irresponsible choice. We are going to choose the irresponsible choice because we're learning. So start in locked mode. So locked mode basically, the database is on complete lockdown, you can't do anything to it, right.

[00:01:05] Which is generally speaking, whitelisting is better than blacklisting, totally. And we will eventually go to something closer to locked mode, but first we're gonna start in test mode. Test mode is wide open, anyone can do anything anywhere in the database. Now you should not push to production like this.

[00:01:24] However, on local host you're probably safe, right. So we'll go ahead and we'll enable it in test mode.
>> Steve Kinney: Setting up our security rules, which are almost like a lack thereof of security rules. And we have our database, there's not much in it yet, which make sense, we just created it.

[00:01:49] Let's actually wire it into our React application. So to do that, we will flip back over. And we're gonna pull in the code for Firestore. So we'll import Firebase slash Firestore, right. If we pulled in all of Firebase we would've gotten Firestore, but we would've also gotten all the code for working with the real time database.

[00:02:11] Chances are we're not using both, right. There's actually nothing stopping you from using both, other than your own sanity. So we can import Firestore, and then what I'll usually do is I'll go a head and I'll do, export const firestore = firebase,
>> Steve Kinney: And it calls it as a function like that.

[00:02:39] All right, so now we've got Firebase and we have a database. That was it, right, we're good to go. We're not actually calling this file anywhere yet, so let's go ahead and do that in application.jsx.
>> Steve Kinney: Here I will simply do import { firestore } from '../firebase', all right.

[00:03:11] Go back over to my application.
>> Steve Kinney: Firestore is defined but not used, that makes total sense because we are in fact defining it but not using it.