{"id":42572,"library":"cypress-mongodb","title":"cypress-mongodb","description":"A Cypress plugin that provides custom commands (createCollection, dropCollection, insertOne, insertMany, findOne, findMany, updateOne, updateMany, deleteOne, deleteMany, aggregate) for interacting with a MongoDB server during end-to-end tests. Current stable version is 7.0.0, released on a periodic cadence. It wraps the MongoDB Node.js driver v7 and supports MongoDB 7-8 and Node 20-24. Key differentiators: it works with both local and remote MongoDB instances, allows per-command overrides for database/collection, and offers a failSilently option to avoid failing tests on expected errors. TypeScript types are included. A known issue is that if your project uses the 'mongodb' package, it must be version 7.x to avoid Webpack compilation errors.","status":"active","version":"7.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/Zaista/cypress-mongodb","tags":["javascript","cypress","plugin","mongodb","mongo","database","db","typescript"],"install":[{"cmd":"npm install cypress-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add cypress-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add cypress-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for connecting to MongoDB. Must be version 7.x.","package":"mongodb","optional":true}],"imports":[{"note":"Use ESM import in cypress.config.js as shown in documentation. CommonJS require may work but official docs use import.","wrong":"const { configurePlugin } = require('cypress-mongodb')","symbol":"configurePlugin","correct":"import { configurePlugin } from 'cypress-mongodb'"},{"note":"Must import from 'cypress-mongodb/dist/index-browser' for browser context (cypress/support/e2e.js). The main entry point is for Node.js (e2e setup).","wrong":"import { addCommands } from 'cypress-mongodb'","symbol":"addCommands","correct":"import { addCommands } from 'cypress-mongodb/dist/index-browser'"},{"note":"Make sure to call addCommands() after import. No default export; named export only.","wrong":"import { addCommands } from 'cypress-mongodb'","symbol":"default (addCommands)","correct":"import { addCommands } from 'cypress-mongodb/dist/index-browser'; addCommands();"}],"quickstart":{"code":"// 1. Install: npm install cypress-mongodb\n\n// 2. In cypress.config.js:\nimport { configurePlugin } from 'cypress-mongodb';\nmodule.exports = defineConfig({\n  env: {\n    mongodb: {\n      uri: process.env.MONGO_URI || 'mongodb://localhost:27017',\n      database: 'testdb'\n    }\n  },\n  e2e: {\n    setupNodeEvents(on, config) {\n      configurePlugin(on);\n    }\n  }\n});\n\n// 3. In cypress/support/e2e.js:\nimport { addCommands } from 'cypress-mongodb/dist/index-browser';\naddCommands();\n\n// 4. In a test:\ndescribe('MongoDB test', () => {\n  it('inserts and finds a document', () => {\n    cy.insertOne({ name: 'Alice' });\n    cy.findOne({ name: 'Alice' }).then(doc => {\n      expect(doc).to.have.property('name', 'Alice');\n    });\n  });\n});","lang":"typescript","description":"Complete setup of cypress-mongodb in Cypress, including configuration and a sample test that inserts and finds a document."},"warnings":[{"fix":"Install mongodb@7.0.0 or later: npm install mongodb@7.0.0","message":"Version 7.x of cypress-mongodb requires mongodb package version 7.x as a peer dependency. If you have mongodb v6, you will get a Webpack compilation error.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use import { addCommands } from 'cypress-mongodb/dist/index-browser';","message":"addCommands must be imported from 'cypress-mongodb/dist/index-browser', not from the main entry point. Using the wrong path will result in an error when Cypress tries to load the browser bundle.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Pass failSilently: true (boolean) instead of failSilently: 'true' (string).","message":"Options object for commands used to accept failSilently as a string 'true'/'false' (see older examples). Now it should be a boolean.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Be explicit: either always use env database by not passing options, or always pass options with expected database.","message":"If you set mongodb.database in env, but then use an options object with a different database name, the options database takes precedence. This can cause confusion if you expect the env database to always apply.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'-24':59 '-8':55 '20':58 '7':54,110 '7.0.0':38 'aggreg':21 'allow':71 'avoid':84,113 'cadenc':43 'command':10,74 'compil':115 'createcollect':11 'current':34 'custom':9 'cypress':2,5,118 'cypress-mongodb':1 'databas':122 'database/collection':77 'db':123 'deletemani':20 'deleteon':19 'differenti':61 'driver':49 'dropcollect':12 'end':30,32 'end-to-end':29 'error':89,116 'expect':88 'fail':85 'failsil':81 'findmani':16 'findon':15 'includ':93 'insertmani':14 'inserton':13 'instanc':70 'interact':23 'issu':96 'javascript':117 'key':60 'known':95 'local':66 'mongo':121 'mongodb':3,26,47,53,69,104,120 'must':107 'node':57 'node.js':48 'offer':79 'option':82 'overrid':75 'packag':105 'per':73 'per-command':72 'period':42 'plugin':6,119 'project':101 'provid':8 'releas':39 'remot':68 'server':27 'stabl':35 'support':52 'test':33,86 'type':91 'typescript':90,124 'updatemani':18 'updateon':17 'use':102 'v7':50 'version':36,109 'webpack':114 'work':63 'wrap':45 'x':111","created_at":"2026-06-05T16:55:37.664514+00:00","updated_at":"2026-06-05T16:55:37.664514+00:00","problems":[{"fix":"Upgrade mongodb to >=7.0.0: npm install mongodb@7.0.0","cause":"Using incompatible version of mongodb (v6) with cypress-mongodb v7.","error":"Module parse failed: Unexpected token (1:8) - You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."},{"fix":"Import { addCommands } from 'cypress-mongodb/dist/index-browser' and call addCommands().","cause":"Imported addCommands from the wrong path or using default export incorrectly.","error":"addCommands is not a function"},{"fix":"Set mongodb.uri in cypress.config.js env and provide database either in env or in command options.","cause":"Missing env.mongodb.uri or database not set and no database option provided to a command.","error":"TypeError: Cannot read properties of undefined (reading 'collection')"}],"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/Zaista/cypress-mongodb","github":"https://github.com/Zaista/cypress-mongodb","docs":null,"changelog":null,"pypi":null,"npm":"cypress-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"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}}