Registry / database / mniam
library5.1.0jsnpmunverified

mniam is a small, opinionated MongoDB facade for the official Node.js native driver (mongodb). Version 5.1.0 wraps the driver's MongoClient to simplify URI parsing, connection management, and collection operations. It provides a lightweight API for CRUD, cursors (with async iteration, toArray, eachSeries, eachLimit), and aggregation pipelines. Key differentiators: minimal abstraction, automatic index creation, and fluent cursor/aggregation builders. Release cadence is sporadic; last update was 2022. Suitable for small projects seeking a thin wrapper without ODM features.

npm install mniam
INSTALL
IMPORT
SIG · MNIAM
M
mniam
databasejavascriptv5.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

database
import { database } from 'mniam'
import database from 'mniam'
database is a named export, not a default export.
types/Collection
import type { Collection } from 'mniam'
import { Collection } from 'mniam'
Collection is a TypeScript type; import as type if using TypeScript with isolatedModules.
database (CommonJS)
const { database } = require('mniam')
const database = require('mniam')
CommonJS requires destructuring to access the exported function.

Connects to a MongoDB instance, creates a collection with an index, inserts a document, queries using async iteration, and performs an aggregation pipeline.

import { database } from 'mniam'; const db = database('mongodb://localhost:27017/mydb'); async function run() { const collection = db.collection({ name: 'users', indexes: [[{ email: 1 }, { unique: true }]] }); // Insert await collection.save({ email: 'alice@example.com', age: 30 }); // Query with async iterator for await (const user of collection.query({ age: { $gt: 25 } }).items()) { console.log(user.email); } // Aggregation pipeline const results = await collection .aggregate() .match({ age: { $gte: 18 } }) .group({ _id: null, avgAge: { $avg: '$age' } }) .toArray(); console.log(results); // Close connection when done db.close(); } run().catch(console.error);
Debug
Known issues
breakingVersion 3.x removed the db.collection() second argument (options); use db.collection({ name, indexes, options }) instead.
fix
Upgrade to mniam@3.x and adapt collection creation calls to use single object parameter.
affects: >=3.0.0
breakingVersion 5.x requires mongodb driver v4+; mongodb v3.x is no longer supported.
fix
Upgrade mongodb to v4.x or v5.x in your dependencies.
affects: >=5.0.0
deprecated.eachSeries and .eachLimit are soft deprecated; prefer async iteration with .items() for new code.
fix
Replace .eachSeries(fn) with for await...of loop over .items() or .toArray()
affects: >=5.0.0
gotchadatabase() does not automatically close connections. You must call db.close() or handle cleanup manually to avoid hanging connections.
fix
Call db.close() in your shutdown logic (e.g., process.on('SIGINT', ...)).
affects: >=1.0.0
gotchaIndex options (e.g., { unique: true }) must be passed inside the index array as a second element, not as a separate argument.
fix
Use indexes: [[{ field: 1 }, { unique: true }]]
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'mniam'
mniam is not installed or not in node_modules. Also, maybe CommonJS require without destructuring.
fix
npm install mniam
Error: MongoDB driver version mismatch: expected mongodb@^4.0.0
Installed mongodb driver version is incompatible with mniam 5.x.
fix
npm install mongodb@4.x
TypeError: db.collection is not a function
database() returned unexpected type (maybe null or undefined due to connection failure).
fix
Check MongoDB connection string and ensure mongod is running.
TypeError: collection.save is not a function
collection() called with missing or incorrect arguments (no name provided).
fix
Ensure collection config includes 'name' property: collection({ name: 'mycollection', indexes: [] })
Upgrade
Version history
5.1.0latest on npm
Audit
Dependencies
mongodboptionalPeer dependency: mniam wraps the official MongoDB Node.js driver (expects mongodb v4.x or v5.x).
Agent activity
4 hits · last 30 days
node
4
Resources
packagemniam
mniam — npm install mniam · libregistry