1

I try a very very basic sample of lokijs with the autosave option, but I cannot save the data...

An idea of my mistake ? (it's an adaptation of a sample found on https://github.com/techfort/LokiJS/wiki/LokiJS-persistence-and-adapters

I use Node v10.14.2 on my PC (windows) with the latest version of lokijs?


const loki = require('lokijs');

var db = new loki('sandbox.db', {
        autoload: true,
        autoloadCallback : databaseInitialize,
        autosave: true, 
        autosaveInterval: 4000
    });

function databaseInitialize() {

  var cu = db.getCollection("Users");
  if (!cu) {
    cu = db.addCollection("Users", {indices: ['name']});
  }
  if (!cu) {
        var now = new Date();
      try{
        cu.insert({
            name : "Mr X",
            email : "Mr_x@gmail.com",
            password : "xyz",
            creation: now
        });
      }
    catch(ex){
        console.log("test exception: "+ ex.message);    
    }
  }
}

Didier68
  • 1,027
  • 12
  • 26

1 Answers1

1

Finally, i found the answer in another sample:

the "autoupdate" option have to be set to every collection !

  db.addCollection("AuthController",  {unique: ['name'] , autoupdate: true } );
Didier68
  • 1,027
  • 12
  • 26