Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to a remote DB: "Another user is already authenticated to this database." #554

Closed
hbd opened this issue Oct 20, 2016 · 3 comments
Labels

Comments

@hbd
Copy link

hbd commented Oct 20, 2016

How can I connect to a MongoDB cluster on Mongo Atlas using mongo-connector?

I have tried to connector to my cluster with the following commands:

First attempt

sudo mongo-connector -m "mongodb://g******:*********@rest-api-data-shard-00-00-xemv3.mongodb.net:27017,rest-api-data-shard-00-01-xemv3.mongodb.net:27017,rest-api-data-shard-00-02-xemv3.mongodb.net:27017/admin?ssl =true&replicaSet=rest-api-data-shard-0&authSource=admin" -a g****** -p "***********" -t http://localhost:9200 -d elastic2_doc_manager

Response:

Logging to mongo-connector.log. Exception in thread Thread-1: Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/site-packages/mongo_connector/util.py", line 90, in wrapped func(*args, **kwargs) File "/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py", line 263, in run main_conn['admin'].authenticate(self.auth_username, self.auth_key) File "/usr/local/lib/python2.7/site-packages/pymongo/database.py", line 1018, in authenticate connect=True) File "/usr/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 434, in _cache_credentials raise OperationFailure('Another user is already authenticated ' OperationFailure: Another user is already authenticated to this database. You must logout first.

Second attempt:

sudo mongo-connector -m "mongodb://rest-api-data-shard-00-00-xemv3.mongodb.net:27017,rest-api-data-shard-00-01-xemv3.mongodb.net:27017,rest-api-data-shard-00-02-xemv3.mongodb.net:27017/admin?replicaSet=rest-api-data-shard-0" -a g********* -p "********" -t http://localhost:9200 -d elastic2_doc_manager

Response:

Logging to mongo-connector.log. Exception in thread Thread-1: Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/site-packages/mongo_connector/util.py", line 90, in wrapped func(*args, **kwargs) File "/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py", line 263, in run main_conn['admin'].authenticate(self.auth_username, self.auth_key) File "/usr/local/lib/python2.7/site-packages/pymongo/database.py", line 1018, in authenticate connect=True) File "/usr/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 439, in _cache_credentials writable_preferred_server_selector) File "/usr/local/lib/python2.7/site-packages/pymongo/topology.py", line 210, in select_server address)) File "/usr/local/lib/python2.7/site-packages/pymongo/topology.py", line 186, in select_servers self._error_message(selector)) ServerSelectionTimeoutError: rest-api-data-shard-00-02-xemv3.mongodb.net:27017: [Errno 54] Connection reset by peer,rest-api-data-shard-00-00-xemv3.mongodb.net:27017: [Errno 54] Connection reset by peer,rest-api-data-shard-00-01-xemv3.mongodb.net:27017: [Errno 54] Connection reset by peer

x/post from http://stackoverflow.com/questions/40162331/how-to-connect-to-remote-mongodb-with-mongo-connector

@ShaneHarvey
Copy link
Contributor

In your first attempt, the problem is that you are specifying the username and password for MongoDB twice. Remove the -a g****** -p "***********" and it should work fine. If you need to authenticate to Elasticsearch you need to use a mongo-connector config file and set the correct authentication options for the Python Elasticsearch client, eg:

{
  "mainAddress": "mongodb://user:pass@mongodb:27017,mongodb:27018,mongodb:27019/admin?ssl=true&replicaSet=name&authSource=admin",
  "verbosity": 1,
  "docManagers": [
    {
      "docManager": "elastic2_doc_manager",
      "targetURL": "http://localhost:9200",
      "args": {
        "clientOptions": {
           "http_auth": ["user", "secret"],
           "use_ssl": true
        }
      }
    }
  ]
}

In your second attempt, it looks like the problem is that you forgot to add ssl=true to the MongoDB connection string. That's why you're getting Connection reset by peer errors.

@hbd
Copy link
Author

hbd commented Oct 20, 2016

Second option worked perfectly. Thanks.

@hbd hbd closed this as completed Oct 20, 2016
@vishaleclass
Copy link

Hi @ShaneHarvey @hbd,
I'm new in this stuff. I have to integrate mongo-db Atlas to Elastic search. I have succefully connected to mongoDB atlas by applying @ShaneHarvey comment however not able to connect to target URL(elastic cloud).
Can you please help me with syntax you had use or can you please share brief description about it ?
I'm also having same kind of issue. I'm trying to connect elasticsearch cloud but no luck. Getting error.


[root@vm02 ~]# mongo-connector -c mongo-connector.json
Traceback (most recent call last):
  File "/usr/bin/mongo-connector", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/mongo_connector/util.py", line 107, in wrapped
    func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/mongo_connector/connector.py", line 1409, in main
    conf.parse_args()
  File "/usr/lib/python2.7/site-packages/mongo_connector/config.py", line 119, in parse_args
    raise errors.InvalidConfiguration(str(exc)).with_traceback(tb)
AttributeError: 'InvalidConfiguration' object has no attribute 'with_traceback'

[root@vm02 ~]# cat mongo-connector.json
{
  "mainAddress": 'mongodb://admin01:password@<fqdn>:27017,fqdb:27017,fqdn:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true/admin?ssl=true&replicaSet=name&authSource=admin',
  "verbosity": 1,
  "docManagers": [
    {
      "docManager": "elastic2_doc_manager",
      "targetURL": "https://46a7532846fd4853929245a0e7edadc8.eu-west-1.aws.found.io:9243",
      "args": {
        "clientOptions": {
           "http_auth": ["elastic", "password"],
           "use_ssl": true
        }
      }
    }
  ]
}


thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants