Search code examples
mongodbmongodb-biconnector

how to connect to multiple mongo instances from a single mongosqld at the same time


I have 2 mongo server say MONGO_A and MONGO_B (both in different servers) and in one server, I have a mongosqld.conf file with which I am able to access one MongoDB (say MONGO_A) in Tableau at a time.

I wanted to know if it is possible for the mongosqld to connect to more than one server at a time, or if there is another way to do this?


Solution

  • I have found the answer.

    • 1st possible way: Using mongosqld and mongo drdl

    You can use the same mongosqld with different ports.

    eg:

    mongosqld --addr 127.0.0.1:3307 --mongo-uri=mongodb://127.0.01:27017 --schema db1.drdl -vv

    mongosqld --addr 127.0.0.1:3309 --mongo-uri=mongodb://192.188.188.39:27017 --schema db2.drdl -vv

    Here 127.0.0.1:27017 is Mongo_A and 192.188.188.39:27017 is Mongo_B both I'm accessing from the same Localhost and same mongosqld with different ports you have to run both these commands in different terminals.

    • 2nd possible way is by using mongosqld as service

    In this case, we need to manually create 2 separate service with 2 different mongosqld conf files in which mongosqld port will be different.

    As I’m using Linux, what I did is I just created two separate services in /etc/systemd/system for mongosqld that had two separate configuration files (Inside which we mention 2 mongo server IPs and 2 different mongosqld ports). Then since I was using clear text authentication I needed to create SSL for both mongosqld services

    ref: https://docs.mongodb.com/bi-connector/v2.13/tutorial/ssl-setup/

    Then finally I was successful in connecting both Mongo Servers.