{"id":43718,"library":"qh-mongodb","title":"MongoDB Node.js Driver","description":"The official MongoDB driver for Node.js, maintained by MongoDB Inc. This package (version 4.10.100) provides async/await support, transaction support, and a modern API for connecting to MongoDB databases. It ships TypeScript types and requires Node.js >= 12.9.0. Key differentiators include full support for MongoDB features like change streams, aggregation, and gridfs, as well as automatic connection pooling and retryable reads/writes. The driver follows MongoDB's release cadence and is actively developed.","status":"active","version":"4.10.100","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mongodb/node-mongodb-native","tags":["javascript","mongodb","driver","official","typescript"],"install":[{"cmd":"npm install qh-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add qh-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add qh-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Optional dependency for client-side field level encryption (FLE)","package":"mongodb-client-encryption","optional":true},{"reason":"Optional dependency for SASL authentication (SCRAM-SHA-256/PLAIN)","package":"saslprep","optional":true}],"imports":[{"note":"ESM import works with Node >= 12. For CommonJS, use `const { MongoClient } = require('mongodb')`.","wrong":"const MongoClient = require('mongodb').MongoClient","symbol":"MongoClient","correct":"import { MongoClient } from 'mongodb'"},{"note":"Note: ObjectID (capital D) deprecated in v4; use ObjectId (lowercase d).","wrong":"const ObjectId = require('mongodb').ObjectID","symbol":"ObjectId","correct":"import { ObjectId } from 'mongodb'"},{"note":"TypeScript: Db type is exported for type annotations.","wrong":"","symbol":"Db","correct":"import { Db } from 'mongodb'"}],"quickstart":{"code":"import { MongoClient } from 'mongodb';\n\nconst uri = process.env.MONGODB_URI ?? 'mongodb://localhost:27017';\nconst client = new MongoClient(uri);\n\nasync function run() {\n  try {\n    await client.connect();\n    const db = client.db('mydb');\n    const collection = db.collection('mycollection');\n    const insertResult = await collection.insertOne({ hello: 'world' });\n    console.log('Inserted document:', insertResult.insertedId);\n    const findResult = await collection.findOne({ hello: 'world' });\n    console.log('Found document:', findResult);\n  } finally {\n    await client.close();\n  }\n}\nrun().catch(console.dir);","lang":"typescript","description":"Connects to MongoDB, inserts a document, and retrieves it using async/await."},"warnings":[{"fix":"Add await client.connect() before any db operations.","message":"In v4, MongoClient.connect() no longer returns a promise that resolves when connected; call connect() explicitly before operations.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use ObjectId from 'mongodb' instead of ObjectID.","message":"The `ObjectID` (capital D) constructor is deprecated in favor of `ObjectId`.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Always call client.close() in a finally block or use the with statement pattern.","message":"MongoClient does not automatically close connections; forgetting to close can cause resource leaks.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Install optional dependency: npm install mongodb-client-encryption.","message":"Using `mongodb` package without `mongodb-client-encryption` installed will cause an error when trying to use FLE.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use async/await or .then() instead of callbacks.","message":"In v4, the callback-based API is no longer supported; all methods return promises.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use insertOne/insertMany, updateOne/updateMany, deleteOne/deleteMany instead.","message":"The `collection.insert()`, `collection.update()`, and `collection.remove()` methods are deprecated in v4.","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'12.9.0':39 '4.10.100':17 'activ':72 'aggreg':51 'api':26 'async/await':19 'automat':57 'cadenc':69 'chang':49 'connect':28,58 'databas':31 'develop':73 'differenti':41 'driver':3,7,64,76 'featur':47 'follow':65 'full':43 'gridf':53 'inc':13 'includ':42 'javascript':74 'key':40 'like':48 'maintain':10 'modern':25 'mongodb':1,6,12,30,46,66,75 'node.js':2,9,38 'offici':5,77 'packag':15 'pool':59 'provid':18 'reads/writes':62 'releas':68 'requir':37 'retryabl':61 'ship':33 'stream':50 'support':20,22,44 'transact':21 'type':35 'typescript':34,78 'version':16 'well':55","created_at":"2026-06-05T17:01:08.684878+00:00","updated_at":"2026-06-05T17:01:08.684878+00:00","problems":[{"fix":"Start MongoDB service: `mongod` or `net start MongoDB` on Windows.","cause":"MongoDB server is not running or is not accessible at the given host/port.","error":"MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017"},{"fix":"Remove `useNewUrlParser: true` from the MongoClient options.","cause":"The `useNewUrlParser` option has been removed in v4.","error":"MongoParseError: option useNewUrlParser is not supported"},{"fix":"Add `await client.connect();` before using `client.db()`.","cause":"MongoClient.connect() not called before using client.db().","error":"TypeError: client.db is not a function"},{"fix":"Check username/password in the connection string and ensure the database user exists.","cause":"Incorrect credentials or missing authentication mechanism.","error":"MongoError: Authentication failed"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mongodb/node-mongodb-native","github":"ssh://git@github.com/mongodb/node-mongodb-native","docs":null,"changelog":null,"pypi":null,"npm":"qh-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}