gpt4 book ai didi

mongodb - 如何使用 mongo-connector 连接到远程 MongoDB?

转载 作者:可可西里 更新时间:2023-11-01 09:29:05 25 4
gpt4 key购买 nike

如何使用 mongo-connector 连接到 Mongo Atlas 上的 MongoDB 集群?

我尝试使用以下命令连接到我的集群:

第一次尝试

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

响应:

记录到 mongo-connector.log。
线程 Thread-1 中的异常:
追溯(最近一次通话):
__bootstrap_inner 中的文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py”,第 801 行
self 运行()
文件“/usr/local/lib/python2.7/site-packages/mongo_connector/util.py”,第 90 行,已包装
func(*args, **kwargs)
运行中的文件“/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py”,第 263 行
main_conn['admin'].authenticate(self.auth_username, self.auth_key)
文件“/usr/local/lib/python2.7/site-packages/pymongo/database.py”,第 1018 行,在 authenticate 中
连接=真)
文件“/usr/local/lib/python2.7/site-packages/pymongo/mongo_client.py”,第 434 行,在 _cache_credentials 中
raise OperationFailure('另一个用户已经通过身份验证'
OperationFailure:另一个用户已通过此数据库的身份验证。您必须先退出。

第二次尝试:

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

响应:

记录到 mongo-connector.log。
线程 Thread-1 中的异常:
追溯(最近一次通话):
__bootstrap_inner 中的文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py”,第 801 行
self 运行()
文件“/usr/local/lib/python2.7/site-packages/mongo_connector/util.py”,第 90 行,已包装
func(*args, **kwargs)
运行中的文件“/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py”,第 263 行
main_conn['admin'].authenticate(self.auth_username, self.auth_key)
文件“/usr/local/lib/python2.7/site-packages/pymongo/database.py”,第 1018 行,在 authenticate 中
连接=真)
文件“/usr/local/lib/python2.7/site-packages/pymongo/mongo_client.py”,第 439 行,在 _cache_credentials 中
writable_preferred_server_selector)
文件“/usr/local/lib/python2.7/site-packages/pymongo/topology.py”,第 210 行,在 select_server
地址))
文件“/usr/local/lib/python2.7/site-packages/pymongo/topology.py”,第 186 行,在 select_servers
self._error_message(选择器))
ServerSelectionTimeoutError: rest-api-data-shard-00-02-xemv3.mongodb.net:27017: [Errno 54] 连接由对等重置,rest-api-data-shard-00-00-xemv3.mongodb.net:27017 : [Errno 54] 连接被对等重置,rest-api-data-shard-00-01-xemv3.mongodb.net:27017: [Errno 54] 连接被对等重置

最佳答案

github issue 上回答.解决方案:

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.

关于mongodb - 如何使用 mongo-connector 连接到远程 MongoDB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40162331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com