← All tutorials

GoCareerGo Tutorials

MongoDB Tutorial

Documents, collections, CRUD, aggregation, Atlas and driver connectivity.

Connecting from Node.js

The official mongodb npm driver is the standard way to talk to MongoDB from a Node.js application.

const { MongoClient } = require('mongodb');

const client = new MongoClient(process.env.MONGODB_URI);
await client.connect();
const db = client.db('shop');
const users = await db.collection('users').find().toArray();