{"id":43065,"library":"mniam","title":"mniam","description":"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.","status":"active","version":"5.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/pirxpilot/mniam","tags":["javascript","mongodb","mongo","db"],"install":[{"cmd":"npm install mniam","lang":"bash","label":"npm"},{"cmd":"yarn add mniam","lang":"bash","label":"yarn"},{"cmd":"pnpm add mniam","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: mniam wraps the official MongoDB Node.js driver (expects mongodb v4.x or v5.x).","package":"mongodb","optional":true}],"imports":[{"note":"database is a named export, not a default export.","wrong":"import database from 'mniam'","symbol":"database","correct":"import { database } from 'mniam'"},{"note":"Collection is a TypeScript type; import as type if using TypeScript with isolatedModules.","wrong":"import { Collection } from 'mniam'","symbol":"types/Collection","correct":"import type { Collection } from 'mniam'"},{"note":"CommonJS requires destructuring to access the exported function.","wrong":"const database = require('mniam')","symbol":"database (CommonJS)","correct":"const { database } = require('mniam')"}],"quickstart":{"code":"import { database } from 'mniam';\n\nconst db = database('mongodb://localhost:27017/mydb');\n\nasync function run() {\n  const collection = db.collection({\n    name: 'users',\n    indexes: [[{ email: 1 }, { unique: true }]]\n  });\n\n  // Insert\n  await collection.save({ email: 'alice@example.com', age: 30 });\n\n  // Query with async iterator\n  for await (const user of collection.query({ age: { $gt: 25 } }).items()) {\n    console.log(user.email);\n  }\n\n  // Aggregation pipeline\n  const results = await collection\n    .aggregate()\n    .match({ age: { $gte: 18 } })\n    .group({ _id: null, avgAge: { $avg: '$age' } })\n    .toArray();\n  console.log(results);\n\n  // Close connection when done\n  db.close();\n}\n\nrun().catch(console.error);","lang":"typescript","description":"Connects to a MongoDB instance, creates a collection with an index, inserts a document, queries using async iteration, and performs an aggregation pipeline."},"warnings":[{"fix":"Upgrade to mniam@3.x and adapt collection creation calls to use single object parameter.","message":"Version 3.x removed the db.collection() second argument (options); use db.collection({ name, indexes, options }) instead.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade mongodb to v4.x or v5.x in your dependencies.","message":"Version 5.x requires mongodb driver v4+; mongodb v3.x is no longer supported.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Replace .eachSeries(fn) with for await...of loop over .items() or .toArray()","message":".eachSeries and .eachLimit are soft deprecated; prefer async iteration with .items() for new code.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Call db.close() in your shutdown logic (e.g., process.on('SIGINT', ...)).","message":"database() does not automatically close connections. You must call db.close() or handle cleanup manually to avoid hanging connections.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use indexes: [[{ field: 1 }, { unique: true }]]","message":"Index options (e.g., { unique: true }) must be passed inside the index array as a second element, not as a separate argument.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2022':67 '5.1.0':17 'abstract':52 'aggreg':47 'api':36 'async':41 'automat':53 'builder':59 'cadenc':61 'collect':30 'connect':27 'creation':55 'crud':38 'cursor':39 'cursor/aggregation':58 'db':82 'differenti':50 'driver':14,20 'eachlimit':45 'eachseri':44 'facad':8 'featur':78 'fluent':57 'index':54 'iter':42 'javascript':79 'key':49 'last':64 'lightweight':35 'manag':28 'minim':51 'mniam':1,2 'mongo':81 'mongocli':22 'mongodb':7,15,80 'nativ':13 'node.js':12 'odm':77 'offici':11 'oper':31 'opinion':6 'pars':26 'pipelin':48 'project':71 'provid':33 'releas':60 'seek':72 'simplifi':24 'small':5,70 'sporad':63 'suitabl':68 'thin':74 'toarray':43 'updat':65 'uri':25 'version':16 'without':76 'wrap':18 'wrapper':75","created_at":"2026-06-05T16:58:00.722138+00:00","updated_at":"2026-06-05T16:58:00.722138+00:00","problems":[{"fix":"npm install mniam","cause":"mniam is not installed or not in node_modules. Also, maybe CommonJS require without destructuring.","error":"Cannot find module 'mniam'"},{"fix":"npm install mongodb@4.x","cause":"Installed mongodb driver version is incompatible with mniam 5.x.","error":"Error: MongoDB driver version mismatch: expected mongodb@^4.0.0"},{"fix":"Check MongoDB connection string and ensure mongod is running.","cause":"database() returned unexpected type (maybe null or undefined due to connection failure).","error":"TypeError: db.collection is not a function"},{"fix":"Ensure collection config includes 'name' property: collection({ name: 'mycollection', indexes: [] })","cause":"collection() called with missing or incorrect arguments (no name provided).","error":"TypeError: collection.save is not a function"}],"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/pirxpilot/mniam#readme","github":"https://github.com/pirxpilot/mniam","docs":null,"changelog":null,"pypi":null,"npm":"mniam","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}}