i am try to use my exiting DB in Lokijs but my autoloadcallback dose not fire using console.log('from add collection don') to know when it fires but it never dose and when i try to add data to db it fails it only work 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(); }
You are setting options in a third variable that is not present, it should be only:
new loki(file, [options]);
adapter
is an option just like the others, like this:
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");
}
}
});
Cheers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.