title: Mongodb cluster Could not find host matching read preference { mode: "primary" } for set rs0
body: <p>I am deploying a mongodb sharding, I have deployed a replica set in two machines:</p>
  
  <pre><code>rs.status()
  
  
  
   "members" : [
      {
          "_id" : 0,
          "name" : "mongo-shard-1:[port]",
          "health" : 1,
          "state" : 1,
          "stateStr" : "PRIMARY",
          "uptime" : 693,
          "optime" : {
              "ts" : Timestamp(1536595866, 1),
              "t" : NumberLong(13)
          },
      },
      {
          "_id" : 1,
          "name" : "rs-mongo-shard-1:[port]",
          "health" : 1,
          "state" : 2,
          "stateStr" : "SECONDARY",
          "uptime" : 665,
          "optime" : {
              "ts" : Timestamp(1536595866, 1),
              "t" : NumberLong(13)
          },
          "optimeDurable" : {
              "ts" : Timestamp(1536595866, 1),
              "t" : NumberLong(13)
          },
      }
  ],
  "ok" : 1,
  "operationTime" : Timestamp(1536595866, 1),
  "$clusterTime" : {
      "clusterTime" : Timestamp(1536595866, 1),
      "signature" : {
          "hash" : BinData(0,"QwasVYlskhD/0CkuF+4usWfwMHI="),
          "keyId" : NumberLong("6599506821294063618")
      }
  }
  
  
  mongo.conf 
  
  
  
  security:  authorization: enabled keyFile: /[path]/mongo-keyfile replication: replSetName: "rs0"
  </code></pre>
  
  <p>and configsvr in three machine and also a mongos in machine.
  I try to add my replica into mongos, but I got an error:</p>
  
  <blockquote>
    <p>"ok" : 0,<br>
     "errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set rs0",
     "code" : 133,
     "codeName" : "FailedToSatisfyReadPreference",</p>
  </blockquote>