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

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

问题描述

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

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.

推荐答案

这是 MongoDB 管理,您可以查看代码作为如何使用mongodb和电子的示例。

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

基本上你可以使用正如您通常在主进程中的 node.js 中使用mongodb,然后通过<与Renderer进程通信a href =https://electronjs.org/docs/api/ipc-renderer =nofollow noreferrer> ipc 模块。

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.

例如:

渲染器流程

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

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

我建议您使用 http://electron.atom.io/

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

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