I am trying to use my existing DB in LokiJS but my autoloadCallback does not fire.
Am using console.log('from add collection don')
to know when it fires but it never does and when I try to add data to the DB it fails. It only works when I set my collection variable locally:
var user = null
db = new loki("myuser.json",{adapter: adapter}, {
autosave: true,
autosaveInterval: 5000,
autoload: true,
autoloadCallback: function(){
db_ready = true;
console.log('from add collection don')
if(db.getCollection("myaccount") == null ){
myusers = db.addCollection("myaccount");
}
}
});
function py_userlogin(username,password,islogin){
myusers.insert({
username:username,
password:password,
islogin:islogin
},function(err,don){
console.log( JSON.stringify(err) + JSON.stringify(don))
});
console.log(myusers.data);
db.saveDatabase();
}