Last active
February 5, 2024 10:27
-
-
Save techfort/66898d95ac8ff133720d to your computer and use it in GitHub Desktop.
LokiJS - save to disk and reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
db.saveDatabase();
then
console.log(users.data);