Embed Mongodb with Electron

≯℡__Kan透↙ 提交于 2019-12-07 17:10:44

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/51094968/embed-mongodb-with-electron

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