0

I would like to know, is there a way we can replicate from one mongo replica set to another via mongo-connector? As per mongo documentation we can connect two mongo instances via mongo-connector by using a command as in the example below, but I would like to pass replica set name or use a configuration file instead of passing server:port name in command line.

Mongo Connector can replicate from one MongoDB replica set or sharded cluster to another using the Mongo DocManager. The most basic usage is like the following:

mongo-connector -m localhost:27017 -t localhost:37017 -d mongo_doc_manager

I also tried config.json option by creating below config.json file but it has failed.

{
    "__comment__": "Configuration options starting with '__' are disabled",
    "__comment__": "To enable them, remove the preceding '__'",

    "mainAddress": "localhost:27017",
    "oplogFile": "C:\Dev\mongodb\mongo-connector\oplog.timestamp",
    "verbosity": 2,
    "continueOnError": false,

    "logging": {
        "type": "file",
        "filename": "C:\Dev\mongodb\mongo-connector\mongo-connector.log",
        "__rotationWhen": "D",
        "__rotationInterval": 1,
        "__rotationBackups": 10,
        "__type": "syslog"        
    },

    "docManagers": [
        {
            "docManager": "mongo_doc_manager",
            "targetURL": "localhost:37010",
            "__autoCommitInterval": null
        }
    ]
}
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Prasanna
  • 141
  • 1
  • 3
  • 17

2 Answers2

1

yes its possible to connect to a replica set or a shard server using mongo connector.

 {
mongo-connector -m <mongodb server hostname>:<replica set port> \
            -t <replication endpoint URL, e.g. http://localhost:8983/solr> \
            -d <name of doc manager, e.g., solr_doc_manager>
}

you can also also pass a connection string to the mongo-connector such as

{
mongo connector -m mongodb://db1.example.net,db2.example.net:2500/?replicaSet=test&connectTimeoutMS=300000

}

to specify specifc config files you can use

{ mongo-connector -c config.json } 

where config.json is your config file.

satish chennupati
  • 2,602
  • 1
  • 18
  • 27
  • Thanks for the quick response. I tried below way but it failed with below exception. mongo-connector -m rs1 -t rs2 -d mongo_doc_manager – Prasanna Sep 12 '16 at 20:38
  • can you paste the exception please ? did you saw the the configurations options page in github from mongo labs https://github.com/mongodb-labs/mongo-connector/wiki/Configuration%20Options – satish chennupati Sep 12 '16 at 20:39
  • I'm trying to post my exception details because of characters limit i'm not able to post. I'm new to this community. Just give a minute. – Prasanna Sep 12 '16 at 20:44
  • another question, is your replica set up and running ? you also need to specify the port number mongo-connector -m : \ -t \ -d – satish chennupati Sep 12 '16 at 20:44
  • i updated my answer. please have a look. you missed port number for your replica set. – satish chennupati Sep 12 '16 at 20:46
  • Logging to mongo-connector.log. Exception in thread Thread-1: Traceback (most recent call last): File "C:\Program Files\Python\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Program Files\Python\lib\site-packages\mongo_connector-2.5.0.dev0-py3.6.egg\mongo_connector\util.py", line 90, in wrapped func(*args, **kwargs) – Prasanna Sep 12 '16 at 20:46
  • File "C:\Program Files\Python\lib\site-packages\mongo_connector-2.5.0.dev0-py3.6.egg\mongo_connector\connector.py", line 268, in run main_conn.admin.command("isdbgrid") File "C:\Program Files\Python\lib\site-packages\pymongo-3.3.0-py3.6-win-amd64.egg\pymongo\database.py", line 478, in command with client._socket_for_reads(read_preference) as (sock_info, slave_ok): File "C:\Program Files\Python\lib\contextlib.py", line 82, in __enter__ return next(self.gen) – Prasanna Sep 12 '16 at 20:47
  • Yes my replica set is up. I created 2 config files for 2 separate mongo instances. Config file 1: ##store data here dbpath=C:\Program Files\MongoDB 2.6 Standard\data ##all output go here logpath=C:\Program Files\MongoDB 2.6 Standard\log\mongo.log logappend=true #port number port=27017 ##log read and write operations diaglog=3 #replica set name replSet=rs1 Config file 2: dbpath=C:\Program Files\MongoDB 2.6 Standard\data2 logpath=C:\Program Files\MongoDB 2.6 Standard\log2\mongo.log #port number port=37017 #replica set name replSet=rs2 – Prasanna Sep 12 '16 at 20:55
  • I tried with below command but again its failed mongo-connector -m rs1:27010 -t rs2:37010 -d mongo_doc_manager – Prasanna Sep 12 '16 at 20:58
  • Do you have any other suggestions? – Prasanna Sep 12 '16 at 22:34
  • in the command : mongo-connector -m rs1:27010 -t rs2:37010 -d mongo_doc_manager I assume rs1 is the replicaset name. however you need to provide your host machine name there and the port should be the one on which replicaset is running on. – satish chennupati Sep 12 '16 at 23:15
  • You can use mongo-connector -c config.json command and get config.json sample from mongo connector's wiki. – Ash Jun 25 '18 at 22:33
0

I'm able to resolve my issue by entering backslash '\' for my windows directory path.Here is my updated config file for reference. Thanks to ShaneHarveyNot able to use Configuration file for connecting to mongo-connector

{
    "__comment__": "Configuration options starting with '__' are disabled",
    "__comment__": "To enable them, remove the preceding '__'",

    "mainAddress": "localhost:27017",
    "oplogFile": "C:\\Dev\\mongodb\\mongo-connector\\oplog.timestamp",
    "noDump": false,
    "batchSize": -1,
    "verbosity": 2,
    "continueOnError": false,

    "logging": {
        "type": "file",
        "filename": "C:\\Dev\\mongodb\\mongo-connector\\mongo-connector.log",
        "__format": "%(asctime)s [%(levelname)s] %(name)s:%(lineno)d - %(message)s",
        "__rotationWhen": "D",
        "__rotationInterval": 1,
        "__rotationBackups": 10,
        "__type": "syslog",
        "__host": "localhost:27017"        
    },  


    "docManagers": [
        {
            "docManager": "mongo_doc_manager",
            "targetURL": "localhost:37017",
            "__autoCommitInterval": null
        }
    ]
}
Prasanna
  • 141
  • 1
  • 3
  • 17