From the course: GraphQL Essential Training

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Finalize the database connectors

Finalize the database connectors - GraphQL Tutorial

From the course: GraphQL Essential Training

Finalize the database connectors

- [Instructor] Now that we have the necessary items to connect to a Mongo database, let's finalize our server to properly connect to the database. So what we're going to do is go inside of our data folder here and create a new file that we'll call dbConnectors. So this is where we're going to connect all over databases to our GraphQL server. So let's go ahead and create a new file in the data folder though, and call this dbConnectors like so .js. And then what we're going to do is let's go ahead and import mongoose like so. And let me just close this to have more screen estate. And what I'm going to do is create an async function to connect to MongoDB. So let's go ahead and do that async function, and we're going to call this connectMongo, and we're going to try to connect to MongoDB. So what we'll do is await our connection to mongoose, and we're going to use the mongodb at a local host like we checked earlier, and we're going to create a widgets database. And then we're going to…

Contents