13

Can I package MongoDB in an Electron app so I don't need to install it on a client's machine? I'm developing an app on OSX and it will probably be used on Windows. Do I need to separately install Mongo on the clients?

David J.
  • 1,753
  • 13
  • 47
  • 96
  • 4
    You'd probably need to require the client to have MongoDB installed. What is your use case? In most cases I would say MongoDB for desktop application storage to be overkill – kontrollanten Oct 25 '17 at 07:35
  • 1
    @kontrollanten I just need a lightweight nosql db to store files and do basic crud operations. There won't be that much data stored, but the files could be fairly large (up to 20mb or so pdfs) – David J. Oct 25 '17 at 07:42

3 Answers3

12

Yes. I have used this method in the past. It brings in mongod.exe and launches it.

Take a look here to see how it is done.

https://github.com/nosqlclient/nosqlclient-electron/blob/master/index.js

Jeffrey Flynt
  • 318
  • 5
  • 8
6

The simple and obvious answer is: No. MongoDB is AFAIK not embeddable, at least not in any sense of the word straightforward.

But the real question is, what problem do you want to solve? Perhaps is PouchDB the database, you want to ship with your app.

Thomas Junk
  • 5,588
  • 2
  • 30
  • 43
  • 2
    I just want to find a nosql db that will let me store files and read/write data that can be bunled with Electron. I can't have the user install the db separately – David J. Oct 25 '17 at 07:43
  • 1
    Why use a DB to store files instead the obvious solution `filesystem`? – Thomas Junk Oct 25 '17 at 07:46
  • 1
    You're right, I don't actually need to store the files with the DB. I'm migrating this from a Firebase app to a solution that will need to work completely offline, hopefully with as little change as possible to the structure of the code. Is PouchDB embeddable? – David J. Oct 25 '17 at 08:03
  • 1
    It is in as far "embeddable", as it is a "client side" DB which is in the context of "Electon" _embedded_. – Thomas Junk Oct 25 '17 at 15:07
  • 3
    @DavidJ. Forgive my French, but using a database to locally store files is utter nonsense. It adds a layer of complexity (and wastes resources!), let alone the fact that FireBase is hardly comparable with MongoDB or PouchDB. So you would have to basically refactor the CRUD anyway. So you can refactor it to use a filesystem. Portable, simple, resource friendly. – Markus W Mahlberg Jul 05 '18 at 07:57
1

You can actually use indexeddb which is a JavaScript-based object-oriented database.

  • what are the practical limitations on the size of the stores in Indexeddb? – Vass Feb 17 '22 at 17:12
  • 1
    @Vass browser storage limitations and eviction criteria is outlined in this post https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Browser_storage_limits_and_eviction_criteria but as mentioned in this thread https://stackoverflow.com/a/59128994/8398300 you can calculate the quota size and prevent eviction of your data. – Sofonias Abathun Feb 22 '22 at 07:41
  • would you say that at the extended size, that the DB is as fast and efficient as mysql for instance? – Vass Feb 22 '22 at 15:32
  • 1
    I would say the database (with or without extended size) could never as efficient as a standalone database instance. Remember indexeddb is running atop the browser and is a much watered down version of a NoSQL database. – Sofonias Abathun Mar 17 '22 at 18:11