MongoDBConnectionService

This service is used internally, but it is also necessary if you want to work with the Input Agent "MongoDB".

XML configuration


Important note: The availability of a service depends on the license purchased and whether the service has been registered in the configuration file ./etc/factory.xml of the Service Factory (changes require server restart!). There you will also find the responsible configuration file for a service, otherwise you can also edit the configuration file of the service directly in the GUI of the service (changes require a service restart!). The default configuration file for this service is ./etc/mongodb.xml.


A new MongoDB database alias can be added with an XML fragment of the following type.

Minimal configuration


<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC
"-//Lobster//DTD Configure 1.0//EN"
"http://www.lobster.de/dtd/configure_1_1.dtd">
 
<Configure class="com.ebd.hub.services.nosql.mongo.MongoDBConnectionService">
<Set name="verbose">true</Set>
<!-- If the MongoDB should be used for _data logging, the alias name MUST be '_data' -->
<Call name="initPool">
<Arg>
<New class="com.ebd.hub.services.nosql.mongo.MongoDBSettings">
<Set name="alias">mydatabase</Set>
<Call name="addDatabaseEntry">
<Arg type="String">mongodb:plain://192.168.111.103:27017</Arg>
<Arg type="String"/>
<Arg type="String"/>
</Call>
<Set name="minSize">0</Set>
<Set name="catalogName">mydatabase</Set>
</New>
</Arg>
</Call>
</Configure>


The parameters have the following meaning.

alias

The database alias to use.

catalogName

The name of the catalogue (schema) within the MongoDB (also called 'database'). If omitted, the alias name is used.

minSize

The initial size of the connection pool when starting the service.

The connection string (here mongodb:plain://192.168.111.103:27017)

Important note: Currently only the authentication method "plain" is supported. This means that when you log on to the MongoDB, the password is transmitted in plain text. You also have to configure your MongoDB accordingly. Please refer to the manufacturer's documentation for this.

Configuration with user and password


<Call name="initPool">
<Arg>
<New class="com.ebd.hub.services.nosql.mongo.MongoDBSettings">
<Set name="alias">mydatabase</Set>
<Call name="addDatabaseEntry">
<Arg type="String">mongodb:plain://localhost:27017</Arg>
<Arg type="String">username:mydatabase</Arg>
<Arg type="String">password</Arg>
</Call>
<Set name="minSize">0</Set>
<Set name="catalogName">mydatabase</Set>
</New>
</Arg>
</Call>


You must specify the database name with the user.

Configuration for MongoDB replica set (cluster)

A replica set is a cluster of n MongoDBs (usually three, with one primary MongoDB and two secondary MongoDBs). If the primary MongoDB is down, one of the secondary MongoDBs takes over. You don't have to do anything for this, it is done automatically, but all participants must be known.


<Call name="initPool">
<Arg>
<New class="com.ebd.hub.services.nosql.mongo.MongoDBSettings">
<Set name="alias">mongodb_cluster</Set>
<Call name="setDatabases">
<Arg>
<Array type="java.lang.String">
<!-- Replica Member 1 with Replica Set Name -->
<Item>mongodb:plain://localhost1:27017/?replicaSet=rs-ips</Item>
<!-- Replica Member 2 -->
<Item>mongodb:plain://localhost2:27017</Item>
<!-- Replica Member 3 -->
<Item>mongodb:plain://localhost3:27017</Item>
</Array>
</Arg>
</Call>
<Call name="setUsers">
<Arg>
<Array type="java.lang.String">
<!-- User for Replica Member 1 -->
<Item>username:mydatabase</Item>
<!-- User for Replica Member 2 -->
<Item>username:mydatabase</Item>
<!-- User for Replica Member 3 -->
<Item>username:mydatabase</Item>
</Array>
</Arg>
</Call>
<Call name="setPasswords">
<Arg>
<Array type="java.lang.String">
<!-- Password for Replica Member 1 -->
<Item>password</Item>
<!-- Password for Replica Member 2 -->
<Item>password</Item>
<!-- Password for Replica Member 3 -->
<Item>password</Item>
</Array>
</Arg>
</Call>
<Set name="minSize">0</Set>
<Set name="catalogName">mydatabase</Set>
</New>
</Arg>
</Call>


As you can see, the first connection string must contain the name of the replica set (here "rs-ips").

Usually, identical usernames, passwords are used on the different MongoDBs and we recommend this, but you could also use different ones. You also must specify the database name for each user and it must always be the same.

If you then use the Input Agent "MongoDB", for example, simply specify the alias (here "mongodb_cluster"), everything else happens automatically in the background.