我目前正在使用 Electron 和 MongoDB 构建一个桌面应用程序。此应用程序的目标是在应用程序的本地范围内(而不是在服务器上)收集和存储各种客户的信息。我用 node.js 对 MongoDB 做了一些研究;但是我还没有找到在 Electron 中使用它的方法。
最佳答案
这是 MongoDB 的 Electron 应用程序管理方面,可以查看代码作为例子了解如何使用mongodb和electron。
https://github.com/officert/mongotron
基本上你可以像在 node.js 中一样使用 mongodb。在 Main 进程中,然后通过 ipc module 与 Renderer 进程通信.
例如:
渲染器进程
<html>
<head></head>
<body>
<script>
const ipc = require('electron').ipcRenderer;
const informationBtn = document.getElementById('information-dialog')
informationBtn.addEventListener('click', function (event) {
ipc.send('create-user')
})
</script>
</body>
<html>
主进程
const ipc = require('electron').ipcMain
const mongo = require('some-mongo-module')
ipc.on('create-user', function (event) {
/* MONGODB CODE */
})
我建议您使用可以在 http://electron.atom.io/ 中找到的入门应用程序。
关于javascript - 我如何将 mongodb 与 Electron 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38479607/