zoukankan      html  css  js  c++  java
  • MongoDb No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve 'rootlocalhost']

    今天在用TP6框架连接 MongoDB ,但是中途遇到了一个问题 :

    No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve 'rootlocalhost']

    ,网上搜了一下,还是有不少人遇到这个问题的,好多说ipv6什么的,但是我个人测试之后发现好像不是这个原因,也可能是我遇到的问题不同吧。

    大家可以定位到这个文件  vendor opthink hink-ormsrcdbconnectorMongo.php 大概 158行 

    原:

    if (empty($config['dsn'])) {
      $config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
    }

    上面是源代码。

    修改之后:
    if (empty($config['dsn'])) {
    $config['dsn'] = 'mongodb://' . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
    }

     我这里主要是他配置MongoDB 连接地址的时候多拼接了一个 $config['username'] ,我是把他去掉了,然后就可以连接成功了,暂时不知道会不会影响到其他地方。希望能帮到大家!

  • 相关阅读:
    python中json.dumps()和json.dump() 以及 json.loads()和json.load()的区分
    Python的函数
    Python的Set容器
    Python的Dict容器
    Python的tuple容器
    Python的List容器
    python 的控制流程
    Python 数据类型
    k8s-Pod调度策略
    K8s创建pod yaml文件详解
  • 原文地址:https://www.cnblogs.com/hurry-up/p/13565589.html
Copyright © 2011-2022 走看看