问题描述
我将 MongoDB 源代码保存在电子源代码中并使用此命令运行 MongoDB:
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) => {
});
上面的命令在开发时工作,但在捆绑后它不工作.我正在使用电子生成器制作捆绑包.MongoDB 源代码位于根级别.
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.
推荐答案
据我所知,MongoDB不能用Electron打包,必须单独安装.引自本网站:https://www.techiediaries.com/electron-data-persistence/
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/
使用 MongoDB 的优缺点
对于将 MongoDB 与 Electron 应用程序结合使用的优点:
For the pros of using MongoDB with Electron apps:
适用于所有 Electron 支持的平台,例如 Windows、Linux和 MAC.所以它不会限制 Electron 的跨平台特性.
Available for all Electron suppored platforms such as Windows, Linux and MAC. So it doesn't limit the cross platform feature of Electron.
可以与 Electron 轻松安装和集成.
Can be installed and integrated easily with Electron.
也有一些缺点:
- 无法与 Electron 捆绑,因此最终用户需要安装它与您的应用程序分开.
- 小型应用的过度杀伤力.
相反,我可以建议使用 NeDB - https://github.com/louischatriot/nedb
Instead, might I suggest using NeDB - https://github.com/louischatriot/nedb
NeDB 使用 MongoDB API 的一个子集,因此您不需要更改太多代码来进行读写.如果您继续阅读我在上面发布的链接,它还包括在 Electron 应用程序中使用 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.
还有其他几个可以嵌入 Electron 的选项,例如 NeDB(Pouch,Loki.js),它们可能更适合您的需求.
There are also several other options available that can embed with Electron like NeDB (Pouch, Loki.js) that might suit your needs better.
** 更新 **
你也许可以使用这个:https://github.com/nosqlclient/nosqlclient-electron
You may be able to use this: https://github.com/nosqlclient/nosqlclient-electron
网站上提供的更多信息:https://www.nosqlclient.com/
More info available on the website: https://www.nosqlclient.com/
看起来它是 Electron 的替代应用程序,完全支持 MongoDB,使用 Electron?
It looks like it's a replacement application for Electron entirely with MongoDB support, using Electron?
这篇关于用 Electron 嵌入 Mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!