Skip to content

Instantly share code, notes, and snippets.

@vasyl-shumskyi
Forked from techfort/LokiSaveReload.js
Created April 11, 2017 19:19
Show Gist options
  • Save vasyl-shumskyi/ef53b5486d8b768ee0da4dec3cd980b7 to your computer and use it in GitHub Desktop.
Save vasyl-shumskyi/ef53b5486d8b768ee0da4dec3cd980b7 to your computer and use it in GitHub Desktop.
LokiJS - save to disk and reload
var loki = require('lokijs'),
db = new loki('test.json'),
db2 = new loki('test.json');
var users = db.addCollection('users');
users.insert({
name: 'joe'
});
users.insert({
name: 'john'
});
users.insert({
name: 'jack'
});
console.log(users.data);
db.saveDatabase();
db2.loadDatabase({}, function () {
var users2 = db2.getCollection('users')
console.log(users2.data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment