我尝试了一个带有自动保存选项的非常基本的lokijs示例,但我无法保存数据……
知道我的错误吗?(这是在https://github.com/techfort/LokiJS/wiki/LokiJS-persistence-and-adapters上找到的一个样本的改编
我在装有最新版本lokijs的PC (windows)上使用Node v10.14.2。
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);
}
}
}发布于 2019-04-04 21:03:56
最后,我在另一个示例中找到了答案:
必须将“自动更新”选项设置为每个集合!
db.addCollection("AuthController", {unique: ['name'] , autoupdate: true } );https://stackoverflow.com/questions/55500433
复制相似问题