Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Which tool allows you to enforce strict schemas and data validation on top of MongoDB
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Database Connection (MongoDB and PostgreSQL) pipeline. Include the setup and basic execution steps.
You are reviewing a Node Database Connection (MongoDB and PostgreSQL) pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Opening a new database connection (or pool) inside every request handler
// Wrong: new connection per request
app.get('/users', async (req, res) => {
const pool = new Pool({ connectionString: process.env.PG_URI });
res.json(await pool.query('SELECT * FROM users'));
});
// Correct: one pool, created once at startup
// config/db.js
export const pool = new Pool({ connectionString: process.env.PG_URI, max: 10 });The Solution //
Calling mongoose.connect() or new Pool() inside a route handler establishes an expensive new connection on every single request instead of reusing one, quickly exhausting the database's max connection limit under real traffic and crashing the server. Create the connection/pool exactly once at application startup, in a dedicated config/db module, and import that single instance everywhere it's needed.
The Error //
Forgetting to await a database call and treating the resulting Promise as the data
// Wrong: user is a pending Promise, not the record
const user = User.findById(id);
console.log(user.name); // undefined / crash
// Correct
const user = await User.findById(id);
console.log(user.name);The Solution //
Every Mongoose/Prisma/pg call returns a Promise because it involves network I/O to a separate process; omitting await means the variable holds a pending Promise object instead of the actual rows, and any property access on it (like user.name) throws or silently returns undefined.