Registry / database / vg-mongo

vg-mongo

JSON →
library2.0.0jsnpmunverified

vg-mongo is a lightweight MongoDB client wrapper built on top of the official mongodb package, providing a simplified interface for common database operations with built-in pagination support. The current stable version is 2.0.0. It simplifies collection access and adds a paginate method for querying documents with limit, page, and sort options. Key differentiator: eliminates boilerplate for MongoDB pagination compared to using the raw mongodb driver.

npm install vg-mongo
INSTALL
IMPORT
SIG · VG-MONGO
V
vg-mongo
databasejavascriptv2.0.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.

default
✓ import vgMongo from 'vg-mongo'
✗ const vgMongo = require('vg-mongo')
Since v2, vg-mongo is ESM-only. Use import instead of require.
default
✓ const vgMongo = require('vg-mongo')
Deprecated: v1 used CommonJS require. New default is ESM import.

Connects to MongoDB, accesses a collection, inserts a doc, and uses paginate to retrieve results.

import vgMongo from 'vg-mongo'; async function run() { // Connect to MongoDB const db = await vgMongo('mongodb://localhost:27017', 'myDatabase'); // Access a collection const myCollection = db.myCollection; // Insert a document await myCollection.insertOne({ name: 'test', value: 1 }); // Paginate results const query = {}; const fields = {}; const options = { limit: 10, page: 1, sort: { _id: 1 } }; const paginatedResults = await myCollection.paginate(query, fields, options); console.log(paginatedResults); // Close connection await db.close(); } run().catch(console.error);
Debug
Known issues
breakingVersion 2.0.0 drops CommonJS support. require() will not work. Use ESM imports.
fix
Change require('vg-mongo') to import vgMongo from 'vg-mongo' in Node 14+ with type: module or .mjs extension.
affects: >=2.0.0
deprecatedThe options object for paginate does not support 'skip' parameter directly. Use page and limit instead.
fix
Replace skip option with page and limit. Page starts at 1, not 0.
affects: >=1.0.0
gotchaThe vgMongo function returns a database proxy. You must use db.collectionName syntax, not db.collection('collectionName').
fix
Use db.myCollection directly (dynamic property) instead of db.collection('myCollection').
affects: >=1.0.0
gotchaPagination function returns an object with docs and total, but does not include totalPages or hasNextPage. Compute manually.
fix
Use paginatedResults.docs and paginatedResults.total. Calculate totalPages = Math.ceil(total / limit).
affects: >=1.0.0
breakingVersion 2.0.0 no longer accepts deprecated mongodb connection options like useNewUrlParser and useUnifiedTopology.
fix
Remove deprecated options from connection string or second argument. For modern mongodb driver, these options are ignored.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'vg-mongo'
npm install missing or wrong path
fix
Run `npm install vg-mongo` in your project root.
Error: The uri parameter must be a string
vgMongo() called with missing or invalid URL
fix
Ensure first argument is a valid MongoDB connection string, e.g., 'mongodb://localhost:27017'.
TypeError: Cannot read properties of undefined (reading 'paginate')
Collection accessed via db.collection('name') instead of db.name
fix
Use direct property access: const myCollection = db.myCollection;
Error: The 'page' option must be a positive integer
page option is 0 or negative
fix
Set page to >=1 (e.g., page: 1). Pages are 1-indexed.
Error: The 'limit' option must be a positive integer
limit is 0 or negative
fix
Set limit to >=1 (e.g., limit: 10).
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
mongodbrequiredUnderlying MongoDB driver for Node.js. vg-mongo delegates all database operations to mongodb.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
vg-mongo — npm install vg-mongo · libregistry