{"id":46798,"library":"webiny-entity-mongodb","title":"Webiny Entity MongoDB Driver","description":"A MongoDB driver for the webiny-entity ORM, providing a persistent storage backend for entity objects. Current stable version is 1.15.1. It wraps the official MongoDB Node.js driver (peer dependency mongodb ^3.1.13) and integrates seamlessly with webiny-entity, offering features like automatic collection management, query building, and attribute persistence. Designed specifically for the Webiny framework but usable standalone. Low release cadence; primarily for internal Webiny JS usage.","status":"active","version":"1.15.1","language":"javascript","source_language":"en","source_url":"https://github.com/webiny/webiny-js","tags":["javascript"],"install":[{"cmd":"npm install webiny-entity-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add webiny-entity-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add webiny-entity-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core MongoDB driver, required as a peer dependency","package":"mongodb","optional":false}],"imports":[{"note":"The package exposes a default export only, not a named export.","wrong":"import { WebinyEntityMongoDb } from 'webiny-entity-mongodb'","symbol":"default","correct":"import WebinyEntityMongoDb from 'webiny-entity-mongodb'"},{"note":"In CommonJS, the default export is assigned to the variable. Named destructuring will result in undefined.","wrong":"const { MongoDbDriver } = require('webiny-entity-mongodb')","symbol":"MongoDbDriver","correct":"const MongoDbDriver = require('webiny-entity-mongodb')"},{"note":"TypeScript types are included; you can use 'import type' to import the constructor type without bundling.","wrong":null,"symbol":"TypeScript types","correct":"import type { MongoDbDriver } from 'webiny-entity-mongodb'"}],"quickstart":{"code":"import WebinyEntityMongoDb from 'webiny-entity-mongodb';\nimport { MongoClient } from 'mongodb';\n\nasync function main() {\n  const client = new MongoClient(process.env.MONGO_URL ?? 'mongodb://localhost:27017');\n  await client.connect();\n  const db = client.db('myapp');\n\n  const driver = new WebinyEntityMongoDb({ db });\n\n  // Example entity (assuming a User entity defined elsewhere)\n  const user = new User();\n  user.name = 'John';\n  await driver.save(user);\n\n  const loaded = await driver.findOne({ name: 'John' });\n  console.log(loaded);\n\n  await client.close();\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Connects to a local MongoDB instance, creates a driver instance, saves and retrieves a user entity."},"warnings":[{"fix":"Ensure you pass `{ db: mongoClient.db(dbName) }`.","message":"The driver's constructor expects an options object with a `db` property (MongoDb.Db instance), not a MongoClient or connection string.","severity":"gotcha","affected_versions":"*"},{"fix":"Define `static entityName = 'EntityClassName'` in your entity class.","message":"All entities must be instances of classes extending `webiny-entity` and have a defined `entityName` static property.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `driver.save(entity, { beforeSave: fn, afterSave: fn })` instead.","message":"The `onBeforeSave` and `onAfterSave` hooks have been deprecated in favor of passing callbacks directly to the driver methods.","severity":"deprecated","affected_versions":"<=1.14.0"}],"env_vars":null,"search_vec":"'1.15.1':26 '3.1.13':37 'attribut':54 'automat':48 'backend':18 'build':52 'cadenc':67 'collect':49 'current':22 'depend':35 'design':56 'driver':4,7,33 'entiti':2,12,20,44 'featur':46 'framework':61 'integr':39 'intern':70 'javascript':74 'js':72 'like':47 'low':65 'manag':50 'mongodb':3,6,31,36 'node.js':32 'object':21 'offer':45 'offici':30 'orm':13 'peer':34 'persist':16,55 'primarili':68 'provid':14 'queri':51 'releas':66 'seamless':40 'specif':57 'stabl':23 'standalon':64 'storag':17 'usabl':63 'usag':73 'version':24 'webini':1,11,43,60,71 'webiny-ent':10,42 'wrap':28","created_at":"2026-06-07T13:01:41.153440+00:00","updated_at":"2026-06-07T13:01:41.153440+00:00","problems":[{"fix":"const db = client.db('mydb'); const driver = new WebinyEntityMongoDb({ db });","cause":"The driver expects a `db` object with a `collection` method. Missing or incorrectly passed `db`.","error":"Error: Cannot read properties of undefined (reading 'collection')"},{"fix":"Add `static entityName = 'MyEntity';` to the entity class.","cause":"The entity class does not have a static `entityName` property.","error":"Error: entity.constructor.entityName is not defined"},{"fix":"Use `import WebinyEntityMongoDb from 'webiny-entity-mongodb'`.","cause":"Importing the package as `import { WebinyEntityMongoDb }` instead of default import.","error":"TypeError: driver.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/webiny/webiny-js#readme","github":"https://github.com/webiny/webiny-js","docs":null,"changelog":null,"pypi":null,"npm":"webiny-entity-mongodb","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-07","next_check":"2026-09-05","install_tag":null}}