{"id":27684,"library":"deepbase-mongodb","title":"DeepBase MongoDB Driver","description":"MongoDB driver for DeepBase, a reactive nested-object database. Version 3.6.9 is the latest stable release. It stores DeepBase data in MongoDB collections using upsert logic, supports atomic $inc/$dec operations, dot-notation nested updates, and multi-driver setups (e.g., MongoDB primary with JSON backup). Requires the deepbase package as a peer dependency. Well-suited for production applications needing scalability and complex queries, with TypeScript types included.","status":"active","version":"3.6.9","language":"javascript","source_language":"en","source_url":"https://github.com/clasen/DeepBase","tags":["javascript","deepbase","mongodb","mongo","driver","database","persist","nested","objects","typescript"],"install":[{"cmd":"npm install deepbase-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add deepbase-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add deepbase-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as peer dependency; this package provides the MongoDB driver for the DeepBase database framework.","package":"deepbase","optional":false}],"imports":[{"note":"Default export only; named export will be undefined at runtime.","wrong":"import { MongoDriver } from 'deepbase-mongodb';","symbol":"MongoDriver","correct":"import MongoDriver from 'deepbase-mongodb';"},{"note":"CommonJS requires accessing the .default property because the package is ESM-first.","wrong":"const MongoDriver = require('deepbase-mongodb');","symbol":"MongoDriver","correct":"const MongoDriver = require('deepbase-mongodb').default;"},{"note":"DeepBase is the core package, not part of this driver. Both packages are needed.","wrong":"import DeepBase from 'deepbase-mongodb';","symbol":"DeepBase","correct":"import DeepBase from 'deepbase';"}],"quickstart":{"code":"import DeepBase from 'deepbase';\nimport MongoDriver from 'deepbase-mongodb';\n\nconst db = new DeepBase(new MongoDriver({\n  url: process.env.MONGO_URL ?? 'mongodb://localhost:27017',\n  database: 'myapp',\n  collection: 'documents'\n}));\n\nawait db.connect();\n\nawait db.set('users', 'alice', { name: 'Alice', age: 30 });\nconst alice = await db.get('users', 'alice');\nconsole.log('Alice:', alice);","lang":"typescript","description":"Shows how to instantiate DeepBase with the MongoDriver, connect to MongoDB, and perform basic get/set operations."},"warnings":[{"fix":"Use import MongoDriver from 'deepbase-mongodb' for ESM, or const MongoDriver = require('deepbase-mongodb').default for CJS.","message":"The package switched to ESM-only in v3.0.0. Older CommonJS require() patterns no longer work without .default.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always provide both database and collection options explicitly.","message":"Using collection option without also setting database may lead to unexpected defaults in future versions.","severity":"deprecated","affected_versions":">=3.6.0"},{"fix":"Verify keys before writing or use transactions/check-exists logic.","message":"The driver uses upsert by default for set operations. If a key is missing, it creates a new document. This can accidentally overwrite data if not careful.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid dots in key names, or escape them if necessary.","message":"Nested operations using dot notation may conflict with MongoDB's interpretation of dots. Ensure keys do not contain dots to avoid unexpected document structure.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use database: 'myapp' instead of base: 'myapp'.","message":"The base/database option was renamed to database in v2.0.0. The old base option is no longer supported.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run: npm install deepbase","cause":"Missing peer dependency deepbase is not installed.","error":"Error: Cannot find module 'deepbase'"},{"fix":"Start MongoDB or adjust the url option. For local development: docker run -d -p 27017:27017 --name mongodb mongodb/mongodb-community-server:latest","cause":"MongoDB server is not running or not accessible at the given URL.","error":"MongoDB connection error: MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017"},{"fix":"Use: const MongoDriver = require('deepbase-mongodb').default;","cause":"CommonJS require without .default on ESM-only package.","error":"TypeError: MongoDriver is not a constructor"},{"fix":"Provide a valid MongoDB connection string starting with mongodb:// or mongodb+srv://","cause":"The url option is missing or has an unsupported protocol.","error":"Error: Invalid scheme, expected mongodb or mongodb+srv"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}