How do i use mongodb with electron?

橙三吉。 提交于 2019-12-03 07:22:25

问题


I'm currently building a desktop application using Electron and MongoDB. The objective of this application is to collect and store information of various customers in the local scope of the application (not on a server). I've done some research into MongoDB with node.js; however I haven't found a way to use it in Electron.


回答1:


This is an electron app for MongoDB management, you can check the code as an example on how to use mongodb and electron.

https://github.com/officert/mongotron

Basically you can use mongodb as you would normally use in node.js in the Main process and then communicate with Renderer process through the ipc module.

For example:

Renderer process

<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>

Main process

const ipc = require('electron').ipcMain
const dialog = require('electron').dialog
const mongo = require('some-mongo-module')

ipc.on('open-information-dialog', function (event) {
  /* MONGODB CODE */
})

I would recommend you to use the get started app that you can find in http://electron.atom.io/



来源:https://stackoverflow.com/questions/38479607/how-do-i-use-mongodb-with-electron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!