A mongo-like interface to browser Web Storage (localStorage and sessionStorage).
// Connection using sessionStorage, i.e. data is cleaned
// when the browser is closed.
var con = new Chongo.Connection(sessionStorage);
var db = con.db('todos'); // "todo" database. Created if necesary.
var todo = db.col('todos'); // "todo" collection. Created if necesary.
// The next lines work as you'd expect.
todo.insert({title: "Buy apples.", completed: false});
var oid = todo.insert({title: "Take the trash out.", completed: false});
todo.update({_id: oid}, {completed: true});
var cur = todo.find();
while(cur.hasNext()){
console.log(cur.next().title)
}
For more on the usage look in the demo
and test
folders.
Each document is stored separately as JSON under a key with the name
$.<db name>.<collection name>.$<ObjectId>
. An index of the documents
in a collection in $natural order is stored under the key
$.<db name>.<collection name>
.
- CRUD
- Indexing.
- TodoMVC demo.
- Minimized build.
- Automatic synchronization with REST server.
- Events.
- Pluggable features for smaller library size.
The code is distributed under MIT license.