Minimongo is a client-side, in-memory MongoDB clone designed for browser and Node.js environments, offering a MongoDB-like API for CRUD operations and query syntax. It supports various local storage backends including IndexedDB, WebSQL (legacy), LocalStorage, and a purely in-memory option, with an autoselection utility. Currently at version 7.1.1, the project aims for stable releases without a strict public cadence, evolving from a 2014 fork of Meteor.js's minimongo package to incorporate more geospatial queries and npm-friendliness. Its key differentiators include hybrid local/remote synchronization with conflict resolution using base documents, replication between database instances, and support for Extended JSON (EJSON). While it offers a substantial subset of MongoDB query features, it does not support the full aggregation pipeline or all operators.
npm install minimongoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing an IndexedDb locally, setting up a mock RemoteDb, creating a HybridDb for combined local/remote operations, and performing basic CRUD and queries with synchronization.
Thoroughly test query selectors against Minimongo's capabilities. For unsupported operations, consider performing data manipulation client-side after fetching or implementing server-side logic.
Prefer using the IndexedDb backend for persistent storage in modern browsers. MemoryDb or LocalStorageDb can be used for simpler, less data-intensive persistence needs.
Wrap callback-based APIs in Promises for easier integration with `async/await` patterns or explicitly use callbacks as demonstrated in the documentation.
Understand and correctly implement the base document concept for `upsert` operations, especially in multi-user or multi-client environments, to ensure proper conflict resolution. Review the documentation on hybrid sync and conflict handling.
Refer exclusively to the `mWater/minimongo` documentation for this specific package. Avoid assuming direct API parity with Meteor's integrated Minimongo.
Ensure you call `.fetch()` on the result of `find()` and provide a callback, e.g., `collection.find(selector).fetch((docs) => { /* handle docs */ });`.Ensure that `IndexedDb` is initialized only once per namespace, or handle database closing and reopening carefully. Check for pending transactions or other open connections.
Refactor your query to use only the supported logical, comparison, element, and array operators listed in Minimongo's documentation. Complex logic may need to be implemented in client-side code after fetching data.
Use ES module `import` syntax (e.g., `import { NamedExport } from 'minimongo';`) instead of `require()`. Ensure your project's `package.json` specifies `"type": "module"` or that files use `.mjs` extension for ESM.