www.alloyteam.com/2016/03/nod…
db.insert(doc, callback)
doc: 支持String, Number, Boolean, Date, null, array以及object类型。如果该字段是undefined类型,将不会被保存 callback(可选): 回调函数,包含参数err以及newDoc,err是报错,newDoc是新插入的文档,包含它的_id字段。
db.find(query, query2, callback)
query: object类型,查询条件。支持使用比较运算符(lte, gte, nin, or, not, $where), 正则表达式进行查询。
query2: 第二个参数, 原来�指定哪些字段需要返回
callback(可选): 回调函数,包含参数err以及docs,err是报错,docs是查询到的文档集。
sort limit skip
sort({field:1 /-1})
1: 正序(小->大)
limit: 返回的记录数
skip: 忽略前面多少条记录
db.update(query, update, options, callback)
解决nedb 存储问题
www.iditect.com/how-to/5429… 总结: renderer中的数据只会存储到indexedDB中,文章认为需要将nedb 相关操作放到main中,然后renderer 和 main process 通信.
I'm pretty new to Electron too, but as far as I gather from the docs & tutorials, interactions with your database should be done in the main process. You should then use ipc or remote to do the communication between your renderer process and your main. That's how I have it set up anyway.
I use ipc to send events with queries etc from my renderer to my main and then send the results back in the same way. That also allows you to listen for the same data change in multiple places in your app. (eg when i remove the 'favourite' status from a contact, that component gets updated but i can also listen for the update in my favourite list at the same time to reload that so it's up to date)