The official MongoDB driver for Node.js, maintained by MongoDB Inc. Current stable version is 4.x (as of this metadata) with active development. Supports MongoDB 4.4+, Node.js 12.9.0+, and ships TypeScript definitions. Provides both promise-based and callback APIs, connection pooling, change streams, transactions, and aggregation pipeline support. Compared to alternatives like Mongoose, it is lower-level and does not include schema validation or ORM features, but offers full control over MongoDB operations and better performance for complex queries.
npm install qp-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to MongoDB, inserts a document into a collection, and prints the inserted id.
Use await client.connect() or client.connect().then(...).
Always use full URI: 'mongodb://localhost:27017' or 'mongodb+srv://user:password@cluster.mongodb.net'
Replace ObjectID with ObjectId in imports and usage.
Use cursor.toArray() or cursor.forEach() with async/await.
Check if client is connected before closing, e.g., if (client.topology?.isConnected()) await client.close();
Ensure URI starts with 'mongodb://' or 'mongodb+srv://' and is properly encoded.
Check username/password and authSource in URI. For SCRAM-SHA-256, ensure driver version >=4.0.
Ensure client.connect() succeeded and 'db' is a Db instance: const db = client.db('test');