Jump to content
John Kouraklis

Embedded MongoDB

Recommended Posts


does anyone have experience with MongoDB?


Can it be used as a standalone file? Without the need for the end user to install a separate server with an app? Like an sqlite stand-alone db?



Share this post

Link to post

Just to get to know MongoDB and what it's about, I once started the hard way and created a really bare-bones just-the-essentials connector to MongoDB: http://github.com/stijnsanders/TMongoWire

So, no, I'm afraid the plain MongoDB isn't quite fit for embedding. A basic install would require a basic mongoDB installation alongside with your software.

What you could do depending on what you would need from the data-component, is store your own list of JSON documents indexed by their "id" value... But that won't allow you to do clever queries like mongo has with the "$" prefixed query fields...

Edited by stijnsanders

Share this post

Link to post

MongoDB benefit is to be installed in its server(s), with proper replication. 
Using it stand-alone is pointless.


Use SQlite3 as embedded database.
It supports JSON https://www.sqlite.org/json1.html efficiently.


In practice, on some production project we used:

- SQLite3 for almost everything (up to 1TB databases) - and we usually create several databases, e.g. per-user DB

- MongoDB for storing huge content (more than 1TB databases) with replication: typically used as an archive service of "cold" data, which can be queried efficiently if you defined the proper indexes


To let all this work from Delphi, we use our OpenSource http://mormot.net ORM, which is able to run efficiently on both storages, with the exact same code.

The WHERE SQL query clauses are even translated on the fly to MongoDB pipelines by the ORM.

One main trick is to put raw data as JSON in the RawJSON or TDocVariant ORM fields, then duplicate the fields to be queried as stand-alone ORM properties, with a proper index. Then you can query it very efficiently.

Edited by Arnaud Bouchez

Share this post

Link to post

I think I will go with the classic sqlite3 approach eventually. MongoDB needs proper setup and this complexity is not justified for the app I am looking at.


Thanks a lot for the input 

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now