{"id":17790,"library":"marsdb","title":"MarsDB Client-Side Database","description":"MarsDB is a lightweight client-side database inspired by Meteor's minimongo implementation, providing a MongoDB-like API for JavaScript environments. It offers a Promise-based interface, observable cursors, and reactive joins, making it well-suited for applications requiring real-time data reactivity. Written in ES6, it operates across various JavaScript platforms including browsers, Electron, NW.js, and Node.js. The current stable version is 0.6.11. The project appears to be in a maintenance phase, with recent activity primarily focused on bug fixes rather than significant new feature development. Its key differentiators include a flexible pluggable storage architecture (supporting in-memory, LocalStorage, LevelUP, and even MongoDB wrappers), a powerful pipeline for data transformation, and compatibility with a wide range of MongoDB query and modifier operations.","status":"maintenance","version":"0.6.11","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/c58/marsdb","tags":["javascript","database","datastore","embedded","levelup","mongoose","linvodb3","nedb"],"install":[{"cmd":"npm install marsdb","lang":"bash","label":"npm"},{"cmd":"yarn add marsdb","lang":"bash","label":"yarn"},{"cmd":"pnpm add marsdb","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Collection is the default export of the 'marsdb' package. Prior to v0.3.7, ESM import syntax might have been inconsistent.","wrong":"import { Collection } from 'marsdb';\nconst Collection = require('marsdb').Collection;","symbol":"Collection","correct":"import Collection from 'marsdb';"},{"note":"For non-ES6 environments (e.g., older browsers, Node.js without specific flags), this side-effect import is necessary to provide global `Promise`, `Set`, and `Symbol` implementations.","wrong":"import { polyfills } from 'marsdb';\nconst polyfills = require('marsdb').polyfills;","symbol":"Polyfills (side effect)","correct":"import 'marsdb/polyfills';"}],"quickstart":{"code":"import Collection from 'marsdb';\n\nasync function runMarsDBExample() {\n  // Create a new collection named 'users'\n  const users = new Collection('users');\n\n  // Clear existing data for a clean run\n  await users.remove({});\n\n  // Insert documents\n  const insertResult = await users.insert([\n    { _id: '1', name: 'Alice', age: 30, city: 'New York' },\n    { _id: '2', name: 'Bob', age: 24, city: 'Los Angeles' },\n    { _id: '3', name: 'Charlie', age: 30, city: 'Chicago' },\n    { _id: '4', name: 'Diana', age: 28, city: 'New York' }\n  ]);\n  console.log(`Inserted ${insertResult.length} users.`);\n\n  // Find users aged 30\n  const agedThirty = await users.find({ age: 30 }).fetch();\n  console.log('Users aged 30:', agedThirty);\n\n  // Find users in New York, sorted by name\n  const nyUsers = await users.find({ city: 'New York' })\n    .sort({ name: 1 })\n    .fetch();\n  console.log('Users in New York (sorted):', nyUsers);\n\n  // Update Alice's age\n  await users.update({ name: 'Alice' }, { $set: { age: 31 } });\n  const updatedAlice = await users.findOne({ name: 'Alice' });\n  console.log('Updated Alice:', updatedAlice);\n\n  // In a real application, observable cursors would react to changes.\n  // For a quickstart, we just fetch all current users.\n  const allUsers = await users.find({}).fetch();\n  console.log('All current users:', allUsers);\n}\n\nrunMarsDBExample().catch(console.error);","lang":"javascript","description":"Demonstrates creating a MarsDB collection, inserting multiple documents, performing find operations with filters and sorting, and updating a document, all using the Promise-based API."},"warnings":[{"fix":"Remove usages of `static` and `method`. Direct object manipulation is now standard. Adjust code that relied on `Document` wrapping.","message":"The `static` and `method` methods were removed from the Collection class. The internal Document wrapping of objects was also removed for performance improvements.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"To retrieve the actual value, you must now call `.fetch()` on the result, e.g., `await users.find({}).count().fetch()`.","message":"The `count()` and `ids()` methods of a Cursor no longer return direct values (a number or an array of IDs) but now return observable cursors themselves.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Install the specific plugin packages you need (e.g., `npm install marsdb-levelup`) and import them separately from `marsdb`.","message":"Core storage implementations (e.g., LevelUP, LocalStorage) and the AngularJS binding were refactored into separate, dedicated npm packages (e.g., `marsdb-levelup`, `marsdb-angular`). They are no longer bundled with the main `marsdb` package.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Ensure the cursor is not executing by awaiting its `whenNotExecuting()` method before applying changes: `await cursor.whenNotExecuting(); cursor.sort({ name: 1 });`","message":"Modifying a Cursor object while it is actively executing (e.g., changing its query or sort parameters) will throw an error. This is to prevent inconsistent states.","severity":"gotcha","affected_versions":">=0.3.10"},{"fix":"Add `import 'marsdb/polyfills';` (ESM) or `require('marsdb/polyfills');` (CommonJS) at the entry point of your application, before any MarsDB usage.","message":"For JavaScript environments that lack native ES6 features like `Promise`, `Set`, and `Symbol`, the `marsdb/polyfills` module must be explicitly imported to provide these globals.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Add `import 'marsdb/polyfills';` or `require('marsdb/polyfills');` at the top of your main application file to ensure Promises are available.","cause":"Running MarsDB in an environment that lacks native Promise support (e.g., older browsers or Node.js without specific flags) without including the necessary polyfills.","error":"ReferenceError: Promise is not defined"},{"fix":"Chain `.fetch()` to the `count()` call to retrieve the actual number: `await users.find({}).count().fetch()`.","cause":"Attempting to call `.count()` on a cursor and expecting a direct number return value. Since v0.5.0, `count()` returns another observable cursor, not the number directly.","error":"TypeError: users.count is not a function"},{"fix":"Use the `whenNotExecuting()` method to safely queue changes: `await cursor.whenNotExecuting(); cursor.sort({ name: 1 });`","cause":"A MarsDB Cursor object was modified (e.g., its query or sorting parameters were changed) while it was actively processing a previous data operation.","error":"Error: Cursor is executing, cannot modify"},{"fix":"Install the specific storage plugin (e.g., `npm install marsdb-localforage`) and import it separately, then apply it to your collection: `import LocalForageManager from 'marsdb-localforage'; const users = new Collection('users', { StorageManager: LocalForageManager });`","cause":"Attempting to use a storage manager like `LocalForageManager` without installing and importing the corresponding `marsdb-localforage` package.","error":"TypeError: Cannot read property 'setStorageManager' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}