{"id":44104,"library":"vg-mongo","title":"vg-mongo","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/visiongroupnyc/vg-mongo","tags":["javascript","mongo","mongodb","client","visiongroup","universal-pattern"],"install":[{"cmd":"npm install vg-mongo","lang":"bash","label":"npm"},{"cmd":"yarn add vg-mongo","lang":"bash","label":"yarn"},{"cmd":"pnpm add vg-mongo","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying MongoDB driver for Node.js. vg-mongo delegates all database operations to mongodb.","package":"mongodb","optional":false}],"imports":[{"note":"Since v2, vg-mongo is ESM-only. Use import instead of require.","wrong":"const vgMongo = require('vg-mongo')","symbol":"default","correct":"import vgMongo from 'vg-mongo'"},{"note":"Deprecated: v1 used CommonJS require. New default is ESM import.","wrong":null,"symbol":"default","correct":"const vgMongo = require('vg-mongo')"}],"quickstart":{"code":"import vgMongo from 'vg-mongo';\n\nasync function run() {\n  // Connect to MongoDB\n  const db = await vgMongo('mongodb://localhost:27017', 'myDatabase');\n\n  // Access a collection\n  const myCollection = db.myCollection;\n\n  // Insert a document\n  await myCollection.insertOne({ name: 'test', value: 1 });\n\n  // Paginate results\n  const query = {};\n  const fields = {};\n  const options = { limit: 10, page: 1, sort: { _id: 1 } };\n  const paginatedResults = await myCollection.paginate(query, fields, options);\n  console.log(paginatedResults);\n\n  // Close connection\n  await db.close();\n}\n\nrun().catch(console.error);","lang":"typescript","description":"Connects to MongoDB, accesses a collection, inserts a doc, and uses paginate to retrieve results."},"warnings":[{"fix":"Change require('vg-mongo') to import vgMongo from 'vg-mongo' in Node 14+ with type: module or .mjs extension.","message":"Version 2.0.0 drops CommonJS support. require() will not work. Use ESM imports.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace skip option with page and limit. Page starts at 1, not 0.","message":"The options object for paginate does not support 'skip' parameter directly. Use page and limit instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use db.myCollection directly (dynamic property) instead of db.collection('myCollection').","message":"The vgMongo function returns a database proxy. You must use db.collectionName syntax, not db.collection('collectionName').","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use paginatedResults.docs and paginatedResults.total. Calculate totalPages = Math.ceil(total / limit).","message":"Pagination function returns an object with docs and total, but does not include totalPages or hasNextPage. Compute manually.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove deprecated options from connection string or second argument. For modern mongodb driver, these options are ignored.","message":"Version 2.0.0 no longer accepts deprecated mongodb connection options like useNewUrlParser and useUnifiedTopology.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'2.0.0':40 'access':44 'add':46 'boilerpl':62 'built':13,31 'built-in':30 'client':11,76 'collect':43 'common':26 'compar':66 'current':36 'databas':27 'differenti':60 'document':52 'driver':72 'elimin':61 'interfac':24 'javascript':73 'key':59 'lightweight':9 'limit':54 'method':49 'mongo':3,6,74 'mongodb':10,19,64,71,75 'offici':18 'oper':28 'option':58 'packag':20 'page':55 'pagin':33,48,65 'pattern':80 'provid':21 'queri':51 'raw':70 'simplifi':23,42 'sort':57 'stabl':37 'support':34 'top':15 'univers':79 'universal-pattern':78 'use':68 'version':38 'vg':2,5 'vg-mongo':1,4 'visiongroup':77 'wrapper':12","created_at":"2026-06-05T17:03:00.413562+00:00","updated_at":"2026-06-05T17:03:00.413562+00:00","problems":[{"fix":"Run `npm install vg-mongo` in your project root.","cause":"npm install missing or wrong path","error":"Cannot find module 'vg-mongo'"},{"fix":"Ensure first argument is a valid MongoDB connection string, e.g., 'mongodb://localhost:27017'.","cause":"vgMongo() called with missing or invalid URL","error":"Error: The uri parameter must be a string"},{"fix":"Use direct property access: const myCollection = db.myCollection;","cause":"Collection accessed via db.collection('name') instead of db.name","error":"TypeError: Cannot read properties of undefined (reading 'paginate')"},{"fix":"Set page to >=1 (e.g., page: 1). Pages are 1-indexed.","cause":"page option is 0 or negative","error":"Error: The 'page' option must be a positive integer"},{"fix":"Set limit to >=1 (e.g., limit: 10).","cause":"limit is 0 or negative","error":"Error: The 'limit' option must be a positive integer"}],"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/visiongroupnyc/vg-mongo#readme","github":"https://github.com/visiongroupnyc/vg-mongo","docs":null,"changelog":null,"pypi":null,"npm":"vg-mongo","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}}