目标计算机积极拒绝,无法连接。

import pymongo
companyclient = pymongo.MongoClient("192-------13:27017")#,username='root',password='pyLN1234!')  #使用MongoClient对象,连接数据库
companydb = companyclient.ln  # 数据库名 esfcomunicate
companydb.authenticate("root", "----")
companycol = companydb["Construction_certificate"]  # collection集合(类似SQL的表)# 
companycol

报错如下


---------------------------------------------------------------------------
ServerSelectionTimeoutError               Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13600/3264604651.py in <module>
      8 companyclient = pymongo.MongoClient("192.1-----")#,username='root',password='pyLN1234!')  #使用MongoClient对象,连接数据库
      9 companydb = companyclient.ln  # 数据库名 esfcomunicate
---> 10 companydb.authenticate("----", "----")
     11 companycol = companydb["---"]  # collection集合(类似SQL的表)#
     12 companycol

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\database.py in authenticate(self, name, password, source, mechanism, **kwargs)
   1162             validated_options)
   1163 
-> 1164         self.client._cache_credentials(
   1165             self.name,
   1166             credentials,

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _cache_credentials(self, source, credentials, connect)
    580 
    581         if connect:
--> 582             server = self._get_topology().select_server(
    583                 writable_preferred_server_selector)
    584 

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py in select_server(self, selector, server_selection_timeout, address)
    220                       address=None):
    221         """Like select_servers, but choose a random server if several match."""
--> 222         return random.choice(self.select_servers(selector,
    223                                                  server_selection_timeout,
    224                                                  address))

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py in select_servers(self, selector, server_selection_timeout, address)
    180 
    181         with self._lock:
--> 182             server_descriptions = self._select_servers_loop(
    183                 selector, server_timeout, address)
    184 

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py in _select_servers_loop(self, selector, timeout, address)
    196             # No suitable servers.
    197             if timeout == 0 or now > end_time:
--> 198                 raise ServerSelectionTimeoutError(
    199                     self._error_message(selector))
    200 

ServerSelectionTimeoutError: 192.168.1.213:27017: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

解决方法

systemLog:
    destination: file
    path: D:\data\log\mongod.log
storage:
    dbPath: D:\data\db

fork=True
logappend=True
bind_ip=0.0.0.0
port=27017

# 数据库路径
dbpath=D:\mongodb-win32-x86_64-windows-4.4.5\data\db
# 日志输出文件
logpath=D:\data\log\mongo.log
# 错误日志是否追加
#logappend=true

bind_ip=0.0.0.0
# 启用日志文件
journal=true
# 过滤无用日志
quiet=true
port=27017

在这里插入图片描述

mongod --config C:\Program Files\MongoDB\mongo.config 

mongod --config "C:\Program Files\MongoDB\mongod.cfg" --install -serviceName "MongoDB"

在这里插入图片描述

systemLog:
    destination: file
    path: D:\data\log\mongod.log
storage:
    dbPath: D:\data\db

net:
  port: 27017
  bindIpAll: true
# #fork=true
# #logappend=True
# bind_ip=0.0.0.0
# port=27017

# # network interfaces
# net:
#   port: 27017
#   bindIp: 0.0.0.0,::  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值