Registry / database / mongodb-utility

mongodb-utility

JSON →
library1.0.30jsnpmunverified

Utility functions for MongoDB Atlas with Node.js TypeScript setup. Version 1.0.30 stable release; low cadence. Provides convenience wrappers for MongoDB operations (connect, get all docs, drop collection, insert many, get compiled model) using Mongoose. Designed for TypeScript projects, relies on environment variables for credentials. Differentiator: simple, opinionated helper functions compared to using raw Mongoose.

npm install mongodb-utility
INSTALL
IMPORT
SIG · MONGODB-UTILITY
M
mongodb-utility
databasejavascriptv1.0.30
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.

getAllDocs
import { getAllDocs } from 'mongodb-utility'
const getAllDocs = require('mongodb-utility').getAllDocs
ESM import only; no default export
connectToTheDatabase
import { connectToTheDatabase } from 'mongodb-utility'
import connectToTheDatabase from 'mongodb-utility'
Named export only
insertMany
import { insertMany } from 'mongodb-utility'
const { insertMany } = require('mongodb-utility')
TypeScript types included; ESM-only, no CommonJS

Connects to MongoDB, compiles a model, retrieves documents, inserts many, then drops collection.

import { connectToTheDatabase, getAllDocs, insertMany, dropCollection, getCompiledModel } from 'mongodb-utility'; import mongoose from 'mongoose'; const enableLogging = true; async function example() { await connectToTheDatabase(mongoose, enableLogging); const schema = new mongoose.Schema({ name: String }); const model = getCompiledModel('User', schema, enableLogging); const docs = await getAllDocs(model, 'users', enableLogging); console.log('Documents:', docs); await insertMany('users', [{ name: 'Alice' }, { name: 'Bob' }], enableLogging); await dropCollection('users', enableLogging); } example().catch(console.error);
Debug
Known issues
breakingall functions require environment variables MONGO_USER, MONGO_PASSWORD, MONGO_PATH to be set; otherwise they throw a runtime error.
fix
Set the environment variables before calling any function. Use dotenv or similar.
affects: >=1.0.0
gotchagetAllDocs expects a mongoose model instance as first argument, not a collection name alone.
fix
Call getCompiledModel first to get the model, then pass it to getAllDocs.
affects: >=1.0.0
gotchainsertMany and dropCollection take collection name as first argument (string), not a model instance.
fix
Provide the string name of the collection, not the Mongoose model.
affects: >=1.0.0
deprecatedNo deprecated warnings reported; package is simple but may not be actively maintained.
fix
Consider using a more maintained library like mongoose directly for production.
affects: >=1.0.0
Errors
Common errors & fixes
Error: `MONGO_USER` environment variable is not set
Missing required environment variable for database credentials.
fix
Set MONGO_USER, MONGO_PASSWORD, MONGO_PATH environment variables before running the script.
TypeError: getAllDocs is not a function
Importing incorrectly; likely used default import instead of named import.
fix
Use `import { getAllDocs } from 'mongodb-utility'` instead of default import.
Cannot find module 'mongodb-utility' or its corresponding type declarations.
Package not installed or TypeScript cannot find types.
fix
Run `npm install mongodb-utility` and ensure tsconfig.json includes this package in `node_modules`.
Upgrade
Version history
1.0.30latest on npm
Audit
Dependencies
mongooserequiredPeer dependency for database operations; imported at runtime
Agent activity
5 hits · last 30 days
node
4
Resources
mongodb-utility — npm install mongodb-utility · libregistry