{"id":16685,"library":"sharedb-mingo-memory","title":"ShareDB Mingo Memory Adapter","description":"sharedb-mingo-memory is an in-memory database adapter for ShareDB, providing a local, fast, and ephemeral data store that supports a subset of MongoDB's query API through the Mingo library. Its primary use cases include accelerating application testing by eliminating external database dependencies and facilitating local development environments. The current stable version is 4.1.0, with a release cadence tied to Node.js LTS versions and new major releases of ShareDB itself, ensuring broad compatibility. Key differentiators include its lightweight, in-memory nature, making it ideal for CI/CD pipelines and quick prototyping, while still offering a familiar MongoDB-like query interface. It integrates seamlessly with ShareDB applications for a mock database experience.","status":"active","version":"4.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/share/sharedb-mingo-memory","tags":["javascript"],"install":[{"cmd":"npm install sharedb-mingo-memory","lang":"bash","label":"npm"},{"cmd":"yarn add sharedb-mingo-memory","lang":"bash","label":"yarn"},{"cmd":"pnpm add sharedb-mingo-memory","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is an adapter for ShareDB and requires it as a peer dependency to function.","package":"sharedb","optional":false}],"imports":[{"note":"While CommonJS `require` is shown in older documentation, ESM `import` is the preferred and modern way. The module typically exports as a default.","wrong":"const ShareDBMingo = require('sharedb-mingo-memory').default;","symbol":"ShareDBMingo","correct":"import ShareDBMingo from 'sharedb-mingo-memory';"},{"note":"This is the classic CommonJS `require` syntax as demonstrated in the package's README, suitable for Node.js environments.","symbol":"ShareDBMingo","correct":"const ShareDBMingo = require('sharedb-mingo-memory');"},{"note":"The `extendMemoryDB` method is a static property of the default export, not a named export itself. It's used for creating a new ShareDBMingo class that extends a specific `MemoryDB`.","wrong":"const { extendMemoryDB } = require('sharedb-mingo-memory');","symbol":"extendMemoryDB","correct":"import ShareDBMingo from 'sharedb-mingo-memory';\nconst CustomDB = ShareDBMingo.extendMemoryDB(SomeOtherMemoryDB);"}],"quickstart":{"code":"import ShareDBMingo from 'sharedb-mingo-memory';\nimport ShareDB from 'sharedb';\n\n// Initialize the in-memory database adapter\nconst db = new ShareDBMingo();\n\n// Initialize ShareDB with the in-memory adapter\nconst backend = new ShareDB({ db });\n\n// Example usage: Create a connection and a document\nconst connection = backend.connect();\nconst doc = connection.get('myCollection', 'myDocument');\n\ndoc.fetch((err) => {\n  if (err) throw err;\n\n  if (doc.type === null) {\n    // Create the document if it doesn't exist\n    doc.create({ title: 'Hello World', content: 'This is an in-memory document.' }, (err) => {\n      if (err) throw err;\n      console.log('Document created:', doc.data);\n      queryDocuments();\n    });\n  } else {\n    console.log('Document already exists:', doc.data);\n    queryDocuments();\n  }\n});\n\nfunction queryDocuments() {\n  const query = connection.query('myCollection', { title: 'Hello World' });\n  query.subscribe((err) => {\n    if (err) throw err;\n    console.log('Query results:', query.results.map(d => d.data));\n    // Remember to unsubscribe or close connection in a real app\n    query.destroy();\n    connection.close();\n  });\n}","lang":"typescript","description":"This quickstart demonstrates how to initialize sharedb-mingo-memory, integrate it with ShareDB, create a document, and perform a basic query against the in-memory database."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 18 or newer. For projects that cannot upgrade, sharedb-mingo-memory v3.x.x should be used.","message":"Node.js v16 is no longer supported. Applications running on Node.js v16 or older will need to upgrade their Node.js environment to at least v18 to use sharedb-mingo-memory v4.0.0 and above.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade your Node.js runtime to version 16 or newer. For projects that cannot upgrade, sharedb-mingo-memory v2.x.x should be used.","message":"Node.js v14 is no longer supported. Applications running on Node.js v14 will need to upgrade their Node.js environment to at least v16 to use sharedb-mingo-memory v3.0.0 and above.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Upgrade your Node.js runtime to version 14 or newer. For projects that cannot upgrade, sharedb-mingo-memory v1.x.x should be used.","message":"Node.js v12 is no longer supported. Applications running on Node.js v12 will need to upgrade their Node.js environment to at least v14 to use sharedb-mingo-memory v2.0.0 and above.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Upgrade to sharedb-mingo-memory v2.1.0 or higher for basic `$aggregate` support. For `$lookup` within `$aggregate`, upgrade to v4.1.0 or higher. Consult the mingo documentation for supported aggregation pipeline stages.","message":"The `$aggregate` operator was not supported in earlier versions (pre-2.1.0) and would throw an error. Support for basic `$aggregate` was added in v2.1.0, and `$lookup` for `$aggregate` was added in v4.1.0.","severity":"gotcha","affected_versions":"<2.1.0"},{"fix":"Upgrade to sharedb-mingo-memory v3.0.1 or higher to remove the dependency on the `process` global, improving compatibility with bundlers and alternative JavaScript runtimes.","message":"The `process` global was previously a requirement, which could cause issues in certain non-Node.js environments. This requirement was dropped in v3.0.1.","severity":"gotcha","affected_versions":"<3.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Refactor your query to avoid `$mapReduce` or consider using a different ShareDB database adapter that supports it (e.g., `sharedb-mongo`).","cause":"The `sharedb-mingo-memory` adapter does not implement the `$mapReduce` MongoDB operator.","error":"Error: $mapReduce is not supported"},{"fix":"Ensure you are using the correct import syntax for your module system. For ESM, use `import ShareDBMingo from 'sharedb-mingo-memory';`. For CommonJS, use `const ShareDBMingo = require('sharedb-mingo-memory');`.","cause":"This error often occurs when attempting to `new` an imported module incorrectly, especially if mixing ESM `import` with CommonJS `require()` patterns or when the module exports a default that isn't directly constructible.","error":"TypeError: ShareDBMingo is not a constructor"},{"fix":"Check the `peerDependencies` of `sharedb-mingo-memory` to ensure your `sharedb` version is compatible. Also, verify that your Node.js runtime meets the minimum version required by `sharedb-mingo-memory` (e.g., v4.x requires Node.js >=18).","cause":"This usually indicates an incompatibility between the version of `sharedb-mingo-memory` and the version of `sharedb` being used in your project, or a Node.js version mismatch.","error":"RangeError: Invalid version: X.Y.Z (sharedb-mingo-memory)"}],"ecosystem":"npm"}