packages/minimongo/README.md
Source code of released version | Source code of development version
minimongo is reimplementation of (almost) the entire MongoDB API, against an
in-memory JavaScript database. It is like a MongoDB emulator that runs inside
your web browser. You can insert data into it and search, sort, and update that
data. This is great if you like the MongoDB API (which you may already be using
on the server), need a way to store data on the client that you've fetched and
are using to render your interface, and want to use that familiar API.
Minimongo is used as a temporary data cache in the standard Meteor stack, to learn more about mini-databases and what they can do, see the project page on www.meteor.com
Minimongo implements the following features, mirroring the MongoDB features:
sort and limit$near with GeoJSON parsingInternally, all documents are mapped in a single JS object from _id to the
document. Besides this mapping, Minimongo doesn't implement any types of
secondary indexes.
Also, currently Minimongo doesn't implement any aggregation features. The full list of incompatible features can be found in the NOTES file.
Besides the MongoDB features, Minimongo implements the following for a better integration with the Meteor stack:
observe and observeChanges APIs, notification callbacks when the result of
a query changes_publishCursor, that results into an
observe callpauseObservers and resumeObservers, for client-side
caches (allow latency compensation to change multiple objects at once w/o a
flicker)saveOriginals and retrieveOriginals are
used to revert the local changesfind accepts a literal function instead of a selector, and a comparison
function for sortingThis part of the implementation is very important for a smooth Optimistic UI experience (also called "Latency Compensation") avoiding an extra flicker.
Let's review the usual Optimistic UI flow:
To implement the last step, Minimongo implements the following:
saveOriginals is called, to take a snapshot of the
state before the update. Internally, it is implemented in a more efficient
copy-on-write style.retrieveOriginals).pauseObservers and
resumeObservers calls, so any user code (such as Blaze) sees the whole
change in one tick (helps to avoid the flicker).