6

I am keeping MongoDB source code inside electron source code and running MongoDB using this command :

const app = require('electron').app;
const child_process = require('child_process');
const dbInstanceDir = app.getAppPath();
const startMongo = dbInstanceDir + mongodb/bin/mongod --dbpath mydbpath --port 27017 --logpath mylogfile

child_process.exec(startMongo, (error, stdout, stderr) => {
});

Above command is working while development but it not working after bundling. I am using electron builder to make bundle. MongoDB source code is at root level.

enter image description here

Rohit
  • 2,987
  • 3
  • 25
  • 50

2 Answers2

5

As far as I know, you cannot package MongoDB with Electron, it must be installed separately. Quoting from this site: https://www.techiediaries.com/electron-data-persistence/

Pros and Cons of Using MongoDB

For the pros of using MongoDB with Electron apps:

  • Available for all Electron suppored platforms such as Windows, Linux and MAC. So it doesn't limit the cross platform feature of Electron.

  • Can be installed and integrated easily with Electron.

There are also some cons:

  • Can't be bundled with Electron so the end users need to install it separately from your application.
  • Overkill for small apps.

Instead, might I suggest using NeDB - https://github.com/louischatriot/nedb

NeDB uses a subset of the MongoDB API so you shouldn't need to alter much code for reading and writing. If you continue reading the link I posted above, it also covers using NeDB within an Electron app.

There are also several other options available that can embed with Electron like NeDB (Pouch, Loki.js) that might suit your needs better.


** UPDATE **

You may be able to use this: https://github.com/nosqlclient/nosqlclient-electron

More info available on the website: https://www.nosqlclient.com/

It looks like it's a replacement application for Electron entirely with MongoDB support, using Electron?

tremor
  • 3,068
  • 19
  • 37
  • 2
    I have already used NeDB. The main problem with NeDB is it load whole database in memory which will hangs the system if memory exhaust, that's why I tried with MongoDB – Rohit Jul 11 '18 at 10:10
  • 3
    i'd like to know why I got a downvote - this answer is correct - you cannot package MongoDB with Electron – tremor Jul 11 '18 at 13:18
  • 2
    @Rohit - updated my answer with a possible alternative. Also, about NeDB - how big is your DB that the memory exhausts? Have you considered breaking it up into multiple DBs? – tremor Aug 13 '18 at 16:37
  • 2
    @fedeteka see author's disclaimer https://github.com/louischatriot/nedb#pull-requests – Nickensoul Jan 25 '19 at 13:49
  • @Nickensoul Thanks! – fedeteka Jan 29 '19 at 20:17
1

A generic solution allowing to embedd precompiled binaries with electron is described here this one ?

A step by step tutorial using electron-root-path package can be found here

user1767316
  • 3,276
  • 3
  • 37
  • 46