148 points · by ca98am79 · 12y ago · 70 comments
Imagine how to fix low-level data corruption on your <Insert your DBMS name> Server.
Unfortunately, in this case, you can't necessarily. One of the issues here is that holding on to handles to multiple collections doesn't do what it seems to, and also doesn't fail. Try running this:
var low = require('lowdb');
var foo = low('foo');
low('bar');
low.on('add', function(collection) {
console.log("this should be foo:", collection);
});
foo.insert({ name: 'foo' }); low('foo').insert({ name: 'foo' })
low('bar').insert({ name: 'bar' })
low('foo').insert({ name: 'foo' })
So never really considered this way of writing or had this bug.But I can see that it's a flaw and unexpected behavior. I'm adding this to the enhancements for the next version.
Thanks for spotting it :)
https://github.com/adewes/blitzdb
It's a serverless, flat-file, document-oriented database which supports indexing and transactions and comes with a built-in ORM layer and a rich query language modeled after MongoDB.
https://github.com/jamesmoss/flywheel
It's no way near as powerful as BlitzDB but I'm slowly adding features to it.
Also benchmarks should be runnable by users :)
The shared global state (see here: https://github.com/typicode/lowdb/blob/481cf43d6b0a52c1cb996...) means that attempting to use more than one collection will cause issues but it will silently succeed. The synchronous file I/O will grind your process to a halt.
If you are serving a mock API for the purpose of local development you might be fine. If you're trying to build any web application at all, this isn't the right choice.
My somewhat ignorant inclination is to suggest that maildir fits this description.
Also interesting is PouchDB[1], another document storage library. It can be used with Node or in the browser through various backends (like IndexedDB), and can even replicate to CouchDB.
First, thanks for all the interest, it’s quite sudden and unexpected.
Actually, LowDB is an extract from JSON Server, a mocking REST server based on plain JSON (https://github.com/typicode/json-server).
So, basically, it's not meant to be used in critical / intensive applications.
Instead, it's much more a new convenient way to store data in simple use cases.
Regarding file writing, if your database is small or if you don't run a cluster of Node processes, you should be fine.
Regarding benchmark, as someone pointed it out, it’s mainly to show that storing to JSON file is fast enough and to compare operations speed. I agree that it says nothing about other databases and LowDB doesn't try to be the fastest either, just fast enough. By the way, 'npm run benchmark' lets you run it on your machine.
However, keep in mind too that LowDB official release is quite recent so it should be improved over time.
Anyway, thanks for all the feedbacks and I hope you’ll have fun with it :)
upward compatible with mongodb.
Ive also used nedb, which is ok but tends to delete the datastore when it runs out of disk space :P
Could you post an issue on https://github.com/louischatriot/nedb with your environment details and how to reproduce this?
var topFiveSongs = low('songs')
.where({published: true})
.sortBy('views')
.first(5)
.value();
If any db engines figure when the dataset is really large and the limit is really small (no idea what the cutoff would be), if instead of sorting and giving the first five, it instead just looks for the 5 largest/smallest. Anyone have any idea on this?For example, I had a 6 million entry table sitting around, and asked for top 5 rows by an unindexed column. With LIMIT 5 applied it told me:
Sort Method: top-N heapsort Memory: 95kB
Without: Sort Method: quicksort Memory: 577595kB
So if Postgres had to store all the 6 million rows sorted it would need 577 MB of work memory. If (see SHOW work_mem) it was below that that would lead to it writing a lot of temporary files to disk: Sort Method: external merge Disk: 144072kB
Note how Postgres is more wasteful with memory usage than disk writes for temp storage.Generally a query that requires you to do a full table scan on a large table should be used sparingly however.
Yes, there are analyzers with the smarts to recognize that indices on particular fields would have helped a given query, but even if the engine's going to auto-create those for you, it then has to scan every row in the table to create the index that first time.
My usecase would be to keep the data for a website in it and keep the datafiles themselves in repository so it can be backed up there, monitored and possibly merged.
You don't see those around anymore.
I think it's fairly safe to assume that this isn't going to be a wise choice for a server back-end.