...

/

Solution: Mongo and Deno

Solution: Mongo and Deno

Go over the solution for the Mongo and Deno challenge.

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:

Press + to interact
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.

  • Line 13: ...