我如何将 mongodb 与电子一起使用? [英] How do i use mongodb with electron?

查看:24
本文介绍了我如何将 mongodb 与电子一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Electron 和 MongoDB 构建一个桌面应用程序.此应用程序的目标是在应用程序的本地范围内(而不是在服务器上)收集和存储各种客户的信息.我用 node.js 对 MongoDB 做了一些研究;但是我还没有找到在 Electron 中使用它的方法.

解决方案

这是一个 MongoDB 管理,可以查看代码作为例子了解如何使用mongodb和electron.

https://github.com/officert/mongotron

基本上你可以像在主进程中的 node.js 中通常使用的那样使用 mongodb,然后通过 ipc 模块与 Renderer 进程通信.p>

例如:

渲染器进程

<html><头></头><身体><脚本>const ipc = require('electron').ipcRenderer;const informationBtn = document.getElementById('信息对话框')informationBtn.addEventListener('点击', function (event) {ipc.send('创建用户')})</脚本></身体><html>

主进程

const ipc = require('electron').ipcMainconst mongo = require('some-mongo-module')ipc.on('create-user', function (event) {/* MONGODB 代码 */})

我建议您使用可以在 http://electron.atom.io 中找到的入门应用程序/

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.

解决方案

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 mongo = require('some-mongo-module')

ipc.on('create-user', function (event) {
  /* MONGODB CODE */
})

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

这篇关于我如何将 mongodb 与电子一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆