Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i use mongodb with electron?

Tags:

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.

like image 701
scroobius Avatar asked Jul 20 '16 11:07

scroobius


People also ask

Can I use MongoDB with Electron?

This is an electron app for MongoDB management, you can check the code as an example on how to use mongodb and electron. 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.

Which database is best for Electron js?

MongoDB. MongoDB is a fantastic NoSQL database with a lot of resources. In MongoDB, a record is a document, which is a data structure with field and value pairs. It has a straightforward API that is simple to incorporate into your Electron application.

Does Electron need a backend?

Since Electron uses Node on the backend, it also has access to the entire npm ecosystem that Node developers have come to rely on. Even though it is built on Node, Electron is used for desktop applications rather than web applications. This can present a new set of challenges.


Video Answer


1 Answers

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/

like image 146
Piero Divasto Avatar answered Nov 04 '22 02:11

Piero Divasto