MongoDB Persistence with OpenHAB 2

(Gianluca Petralia) #21

I’m trying just today to use OH2 with mongodb.
I followed the guide to configure oh1 to oh2, configuring addons,cfg and runtime.cfg as explained in
I imported the jre and see the bundle active in openhab karaf container,
I created a mongodb.cfg in conf/services folder to config the server, database and collection.
But unfortunately I receive the following warn:
16:02:21.603 [WARN ] [ig.dispatch.internal.ConfigDispatcher] - Could not parse line ‘mongodb://<>:2701’
I don’t know what I’ve to do to fix it.
Can you help me?

(Angelos) #22

add the following line as the first line in your mongodb.cfg:


and then fix correctly the config parameters as described here:

(Angelos) #23

I added your issue in

(blackpi) #24

Hello, I am trying to install the MongoDB in Openhab but I can’t find the *.jar file, could anyone tell me where to find or download the *.jar file?

Blockquote Download the latest *.jar manually from:

This link does not work anymore,

Thank you

(Angelos) #25

(blackpi) #26

Thank you very much

(blackpi) #27

Hello again, I have placed de *.jar file, I have configured the .cfg and the .persist files and I have seen with the OH console that the service is active, but, where does the data get storaged? How can I acccess to it?

Thank you

(Angelos) #28

did you install and configure the Mongo Database?
Why mongodb by the way?
what do you want to do with a persistence db?

(blackpi) #29

Yes I have installed de mongodb and I have read that the data is stored in the path /data/db but I cant see anything there, what configurations have to be done? I have installed it, created the path /data/db and then used it to configure the port in the same place that in the .cfg of openhab using this:

sudo mongod --port 27017 --dbpath /data/db/ --fork --logpath /data/mongodb1.log

I have installed mongodb because I want to have a database to store the information of my sensor in my rasp. I am still a begginer and if I dont get it I have thougth to install a MySQL database instead of the MongoDB. What is the problem with a persistence db?

(Angelos) #30

There is no problem (on the contrary…). There are many options and some fit better to each cause.
What is your goal? To store only (for restoreOnStartup)? To display in graphs? To replicate/export data to another system?

In any case, if you go ahead with Mongo, you need to read:

Keep in mind that:

  1. Not many OH2 users use MongoDB as a persistence storage destination
  2. The binding is not “officially” checked for compatibility with OH2
  3. There is maintenance involved with each DB

Describe your goal and we can give some better options

Read also:

(blackpi) #31

My goal is to restoreOnStartup, to display in graphs and to maybe in a future to replicate/export data to another system. I want a system that is the most flexible as possible. After your comment, I think that a MySQL database is better, I don’t know if it is easy to make the graphs with it but maybe I can use another tool as ThingSpeak or Xively.

(Angelos) #32

Now we are talking :slight_smile:

best option (by far): mapdb
MySQL is way slower than MapDB for this purpose

one of the best options: InfluxDB+Grafana persistence and graphing

You can go with a 3rd one here: MySQL or use Influx. MySQL is more flexible here (export/replicas)

You can also achieve all 3 goals with MySQL as your persistence service. Grafana can also use MySQL as the backend DB and you can also do restoreOnStartup from MySQL.

If you want to use only 1 persistence service, go with MySQL using the JDBC driver.

For your setup, I would recommend a triple persistence configuration: Map + Influx + MySQL
Make sure that your host has enough RAM (~2G) to support all 3 :slight_smile:

(blackpi) #33

Well, I am using a Rasp 3 b+ so my RAM is 1GB. So I think after reading you that the best option is to install MySQL with JDBC driver. That driver that you linked me is the same that we can find in the paper UI / add-ons / persistence, “JDBC Persistence MySQL” ?

do I have to download MySQL from the official page and later configure the JDBC driver ?

Then I can use the Grafana to graph the data

And what about the storage in the cloud, what would you recommend me?

Thank you very much

(Angelos) #34

Yes to all 3 :slight_smile:

Directly from OH2 (configuring the persistence service to connect to a Cloud DB): I wouldn’t recommend this due to latency. It can be done but it’s not fast enough and you may experience problems. It’s better to have a local DB.
It also depends if you want to have DB Access on the Cloud or just a backup destination.
For simple backup: Write a script that exports daily the local MySQL DB and ships it over to the cloud destination.
If you want DB Access on the Cloud you can take a look at:
Export MySQL->Import in Azure