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 install mongodb
yarn add mongodb
pnpm add mongodb
Import
import { MongoClient } from 'mongodb';Quick Example
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
| Package | mongodb |
| Category | Database |
| Weekly Downloads | 5M+ |
| License | Apache-2.0 |
| Install | npm install mongodb |
Related Packages
Mongoose is the most popular Object Data Modeling (ODM) library for MongoDB and Node.js, providing a…
Prisma is a next-generation Node.js and TypeScript ORM that provides a declarative data modeling lan…
redis (node-redis) is the official Redis client for Node.js, providing a full-featured interface to …
Dynamoose is a modeling tool for Amazon DynamoDB, providing a Mongoose-inspired API for defining sch…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.