MongoDB driver for Node.js that wraps the official MongoDB driver with a lazy connection management pattern and async/await-friendly API. Current stable version is 4.0.2, requires Node >=16.20.1, and is released infrequently (last release 2023). Key differentiators vs mongojs: promise-only (no callbacks), lazy connection (supports async connection info via Promises), proxy-based collection access (db.collectionName instead of db.collection('name')). Compared to the official mongodb driver, mongoist automatically manages connections internally, eliminating boilerplate connection code and enabling easy module export of a not-yet-connected db instance.
npm install mongoistNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to a MongoDB database using a connection string, performs find, insert, and count operations with async/await.
Upgrade Node.js to version >=16.20.1
Replace `db.collection('foo')` with `db.foo`Use `const db = mongoist(connectionString)` without `new`.
Use the explicit `db.collection('name')` method for collection names containing dots, dashes, or other special characters.Use `await` or `.then()` to handle results; remove callback parameters.
Use `await db.close()` or `.then()` to ensure connection is closed.
Use `import mongoist from 'mongoist'` (default import) instead of `import { mongoist } from 'mongoist'`.Include credentials in the connection string: `mongoist('mongodb://user:pass@host:port/db')`Run `npm install mongodb` (mongoist lists `mongodb` as a peer dependency).
Ensure you call `await db;` or use `db` inside an async function after the promise resolves.
Verify MongoDB is running (`mongod`) and the connection string is correct: `mongodb://localhost:27017/mydb`