I needed to store data from another project (<ahref="https://github.com/louischatriot/braindead-ci"target="_blank">Braindead CI</a>). I needed the datastore to be standalone (i.e. no dependency except other Node modules) so that people can install the software using a simple `npm install`. I couldn't find one without bugs and a clean API so I made this one.
`db.update(query, update, options, callback)` will update all documents matching `query` according to the `update` rules:
*`query` is the same kind of finding query you use with `find` and `findOne`
*`update` specifies how the documents should be modified. It is either a new document which will replace the matched ones, or a set of modifiers. The available modifiers are `$set` to change a field's value and `$inc` to increment a field's value. You cannot use mixed updates with both modes (that doesn't make sense anyway)
*`options` is an object with two possible parameters: `multi` (defaults to `false`) which allows the modification of several documents if set to true, and `upsert` (defaults to `false`) if you want to insert a new document corresponding to the `update` rules if your `query` doesn't match anything
*`callback` (optional) signature: err, numReplaced, upsert. `numReplaced` is the number of documents replaced and `upsert` is set to true if the upsert mode was chosen and a document was inserted
It is pretty fast on the kind of datasets it was designed for (10,000 documents or less). On my machine (3 years old, no SSD), with a collection with 10,000 documents:
Read, update and deletion times are pretty much non impacted by the number of concerned documents. Inserts, updates and deletions are non-blocking. Read will be soon, too (but they are so fast it is not so important anyway).
You can run the simple benchmarks I use by executing the scripts in the `benchmarks` folder. They all take an optional parameter which is the size of the dataset to use (default is 10,000).
For now, a copy of the whole database is kept in memory. For the kind of datasets expected this should not be too much (max 20MB) but I am planning on stopping using that method to free RAM and make it completely asynchronous.