Generate a MongoDB Database for a GraphQL Backend

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

We will be setting up our GraphQL backend and creating a new MongoDB database.

Start by cloning the backend repo and installing the dependencies. After that, you need to use the seed file provided to generate a new database by running node src/seed.js.

Once you have a database you can run the project and navigate to [localhost:3000/graphiql](http://localhost:3000/graphiql) and explore the GraphQL IDE.

Kevin Cunningham: [0:00] To be able to create our GraphQL frontend, I've created a GraphQL backend. The code's in a repo. When you first get it, we should run yarn install, which will install in all of the package dependencies.

[0:11] This project expects a Mongo backend. As you'll see, it'll try to connect to a local host and create a new database called mysurfshop. I've also created a seed file that you can use to seed your database.

[0:26] This is my Mongo client Robo 3T. At the moment, I don't have that mysurf database, so I'll open my terminal and I'll run node src/seed.js. That will create the database and insert 1,000 craft into it.

[0:40] Now mysurfshop is here. Inside my collections I have crafts. There's 1,000 of them with randomly generated brands, types, names, prices, ages, and owner IDs. Some of them don't have owner IDs, like this one, so that's available for purchase. Each owner ID references a randomly generated owner, and owners have first names, last names, and emails.

[1:04] Once our database has been seeded, we just need to run it. Back in my terminal, I'll run npm run dev, which will start my backend. It will have my log message that's listening on port 3000.

[1:16] I navigate to that URL, see that there's a route not defined, but if I go to GraphiQL, you'll see I have a GraphQL interface. Feel free to explore, see what queries have been set up, what mutations have been set up.

[1:30] Throughout this course, we're going to see how we can use queries in our Vue 3 frontend to get crafts and owners. We'll also see how we can use mutations to be able to add crafts and update them.

Mohammed Zeeshan
Mohammed Zeeshan
~ 2 years ago

Hi, it would have been really really helpful if you could show how to connect to mongodb and robo 3t. Been stuck for the second weekend, exploring tutorials to get that part working :(

Mohammed Zeeshan
Mohammed Zeeshan
~ 2 years ago

Hi awesome folks, can anyone show how to connect the database? 🥹😭🙏

When i enter the the url "mongodb://localhost/mysurfshop" inside Robo3T it doesn't accept and i get an error

Lucas Minter
Lucas Minter
~ 2 years ago

Hey Mohammed, this would be a great question to ask in the egghead Discord. We have a channel where learners can ask for help if you are still stuck on this error.

Markdown supported.
Become a member to join the discussionEnroll Today