Search⌘ K
AI Features

Solution: Mongo and Deno

Explore the integration of MongoDB with Deno by establishing database connections, defining schemas, and setting up GraphQL types, queries, and mutations. This lesson guides you through creating resolvers to build a fully functional GraphQL endpoint backed by MongoDB using Deno.

To solve this challenge, we need three essential steps. Let’s take a look at them below.

Step 1: Establishing a MongoDB connection

First, we need to establish the MongoDB connection:

TypeScript 3.3.4
const app = new Application();
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.response.headers.set("X-Response-Time", `${ms}ms`);
});
const client = new MongoClient();
// Create connection object
await client.connect("mongodb://localhost:27017");

Explanation

  • Lines 1–8: We create and configure a new instance of a Deno application.

  • Line 10: We create a new MongoDB client instance. ...