程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Loki js 不在节点 js 中永久存储数据大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Loki js 不在节点 js 中永久存储数据?

开发过程中遇到Loki js 不在节点 js 中永久存储数据的问题如何解决?下面主要结合日常开发的经验,给出你关于Loki js 不在节点 js 中永久存储数据的解决方法建议,希望对你解决Loki js 不在节点 js 中永久存储数据有所启发或帮助;

我写了一个简单的nodeJs访问者程序。这里我想存储这个程序的执行日期。执行是指使用node index.Js命令运行这个程序。

第一次运行该程序时,它会将数据({execution-time: datE})存储到 db.Json 文件中。但下次运行该程序时,旧数据将被删除并插入新数据。

但我想保留所有以前的数据和新数据。

index.Js

const colLECTION = 'build';
const db_name = "db.Json";
const UPLOAD_PATH= "database";
const Loki = require("lokiJs");

const db = new Loki(`${UPLOAD_PATH}/${db_name}`);

const col = db.getCollection(ColLECTION) || db.addCollection(ColLECTION );

col.insert({'execution-date':new Date()})

db.saveDatabase();


console.log(`@R_172_10586@l number of execution of this program : ${Col.chain().data().length} `);

这里我得到以下结果

@R_172_10586@l number of execution of this program : 1          #first run
@R_172_10586@l number of execution of this program : 1          #second run
@R_172_10586@l number of execution of this program : 1          #third run

预期输出

@R_172_10586@l number of execution of this program :1   #first run
@R_172_10586@l number of execution of this program :2   #second run
@R_172_10586@l number of execution of this program :3   #third run

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Loki js 不在节点 js 中永久存储数据全部内容,希望文章能够帮你解决Loki js 不在节点 js 中永久存储数据所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。