Search⌘ K
AI Features

Exercise: Read User Data from the Database

Understand how to connect a GraphQL backend to MongoDB by defining Mongoose schemas and implementing resolvers. This lesson guides you through reading user data, querying by author, and testing your GraphQL server with database integration.

It’s time to finish our integration with MongoDB. To do so, we must add a Mongoose schema for the users collection and update the remaining resolvers.

As before, this exercise provides a starter code, a walkthrough of the changes we need to implement, and, in case we get stuck, a solution code.

Exercise source code

To get the source code for this exercise, run the following command in the project’s repository:

git checkout db-resolver-exercise

Practice

...
{
  "ext": "js,graphql",
  "delay": 2000
}
Practice demo

How to run the application

Our ...