🗄️
Database5M+/wkApache-2.0

mongodb

mongodb is the official MongoDB Node.js driver that provides a direct interface to MongoDB databases with full support for all MongoDB features including CRUD o

Installation

npm
npm install mongodb
yarn
yarn add mongodb
pnpm
pnpm add mongodb

Import

ESM
import { MongoClient } from 'mongodb';

Quick Example

usage
import { MongoClient } from 'mongodb';

const client = new MongoClient('mongodb://localhost:27017');
await client.connect();

const db = client.db('mydb');
const users = db.collection('users');

await users.insertOne({ name: 'Alice', age: 30 });
const user = await users.findOne({ name: 'Alice' });

About mongodb

mongodb is the official MongoDB Node.js driver that provides a direct interface to MongoDB databases with full support for all MongoDB features including CRUD operations, aggregation pipelines, change streams, transactions, GridFS for large file storage, and client-side field-level encryption. The driver manages connection pooling, automatic retry for transient network errors, server selection for replica sets, and topology monitoring. Operations use a fluent API: collection.find({ age: { $gt: 18 } }).sort({ name: 1 }).limit(10).toArray(). The driver supports the full MongoDB query language including comparison, logical, array, element, and geospatial operators. The aggregation framework enables complex data transformations through pipeline stages like $match, $group, $project, $lookup (JOIN), $unwind, and $facet. Change streams provide real-time notifications when data changes, useful for event-driven architectures. The driver includes TypeScript definitions with generic types for strongly-typed collection operations. While most Node.js developers use Mongoose for its schema validation and middleware features, the native driver is preferred when you need direct access to all MongoDB features, maximum performance, or are building tools that work with arbitrary collection schemas.

Quick Facts

Packagemongodb
CategoryDatabase
Weekly Downloads5M+
LicenseApache-2.0
Installnpm install mongodb

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.