Update README.md

pull/2/head
Louis Chatriot 11 years ago
parent ce71d48392
commit e5b078b9d9
  1. 11
      README.md

@ -25,6 +25,7 @@ npm test // You'll need the dev dependencies to test it
It's a subset of MongoDB's API (the most used operations). The current API will not change, but I will add operations as they are needed. Summary of the API: It's a subset of MongoDB's API (the most used operations). The current API will not change, but I will add operations as they are needed. Summary of the API:
* <a href="#creatingloading-a-database">Creating/loading a database</a> * <a href="#creatingloading-a-database">Creating/loading a database</a>
* <a href="#compacting-the-database">Compacting the database</a>
* <a href="#inserting-documents">Inserting documents</a> * <a href="#inserting-documents">Inserting documents</a>
* <a href="#finding-documents">Finding documents</a> * <a href="#finding-documents">Finding documents</a>
* <a href="#counting-documents">Counting documents</a> * <a href="#counting-documents">Counting documents</a>
@ -87,6 +88,16 @@ db.users.loadDatabase();
db.robots.loadDatabase(); db.robots.loadDatabase();
``` ```
### Compacting the database
Under the hood, NeDB's persistence uses an append-only format, meaning that all updates and deletes actually result in lines added at the end of the datafile. The reason for this is that disk space is very cheap and appends are much faster than rewrites since they don't do a seek. The database is automatically compacted (i.e. put back in the one-line-per-document format) everytime your application restarts.
You can manually call the compaction function with `yourDatabase.persistence.compactDatafile` which takes a `callback(err)` as argument.
You can also set automatic compaction at regular intervals with `yourDatabase.persistence.setAutocompactionInterval(interval)`, `interval` in milliseconds (a minimum of 5s is enforced), and stop automatic compaction with `yourDatabase.persistence.stopAutocompaction()`.
Keep in mind that compaction takes a bit of time (not too much: 130ms for 50k records on my slow machine) and no other operation can happen when it does, most of the projects actually don't need to use it.
### Inserting documents ### Inserting documents
The native types are `String`, `Number`, `Boolean`, `Date` and `null`. You can also use The native types are `String`, `Number`, `Boolean`, `Date` and `null`. You can also use
arrays and subdocuments (objects). If a field is `undefined`, it will not be saved (this is different from arrays and subdocuments (objects). If a field is `undefined`, it will not be saved (this is different from

Loading…
Cancel
Save