# Could not find host matching read preference mode nearest for set rs0

**URL:** <https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596>\
**Category:** Percona Server for MongoDB\
**Created:** [December 21, 2021, 3:05pm UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596 "2021-12-21T15:05:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon17965173](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon17965173](https://forums.percona.com/u/anon17965173)\
**Post date:** [December 21, 2021, 3:05pm UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596/1 "2021-12-21T15:05:48Z")

</div>

In a new cluster, deploying from helm I am getting `FailedToSatisfyReadPreference`

```auto
{"t":{"$date":"2021-12-21T02:48:12.339Z"},"s":"I", "c":"NETWORK", "id":4333208, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM host selection timeout","attr":{"replica
Set":"rs0","error":"FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \"nearest\" } for set rs0"}}
Error: connect failed to replica set rs0/percona-db-psmdb-db-rs0-0.percona-db-psmdb-db-rs0.default.svc.cluster.local:27017,percona-db-psmdb-db-rs0-2.percona-db-psmdb-db-rs0
.default.svc.cluster.local:27017,percona-db-psmdb-db-rs0-1.percona-db-psmdb-db-rs0.default.svc.cluster.local:27017 :

```

One imageins to configure `replsets[0].configuration` which is the `custom config for mongod in replica set ` according to docs, how could one define `ReadPreference` in here to workaround the 4.4 bug I read about in a neighbouring thread. So I am looking at `replication.localPingThresholdMs` at [https://docs.mongodb.com/manual/reference/configuration-options/](https://docs.mongodb.com/manual/reference/configuration-options/) and **Read Preference for Replica Sets** [https://docs.mongodb.com/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection](https://docs.mongodb.com/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection) because `nearest` option does not seem to work for me, even though primary should be default according to Percona docs.

One cannot help to wonder how these parameters set, would this happen to be correct parameters in values.yaml, i.e.:

```auto
replsets:
  - name: rs0
    size: 3
    configuration: 
       readPreference: primaryPreferred

```

MongoDB Logs give me:

> Unrecognized option: readPreference

I also tried:

```auto
    configuration: |
      replication:
        ReadPreference: primaryPreferred

```

yielding

```auto

Unrecognized option: replication.ReadPreference

```

So I gave up on that and redployed with lower mongo count (2 instead of 3) and now I can connect to the RS. When I want to show all dbs, I get now:

```auto
> show dbs
uncaught exception: Error: listDatabases failed:{
        "topologyVersion" : {
                "processId" : ObjectId("61c27b0b330f6a6fe4fd985c"),
                "counter" : NumberLong(1)
        },
        "ok" : 0,
        "errmsg" : "not master and slaveOk=false",
        "code" : 13435,
        "codeName" : "NotPrimaryNoSecondaryOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs/<@src/mongo/shell/mongo.js:147:19
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:99:12
shellHelper.show@src/mongo/shell/utils.js:943:13
shellHelper@src/mongo/shell/utils.js:825:15
@(shellhelp2):1:1

```

and then this:

```auto

> db.createCollection("test")
uncaught exception: Error: error doing query: failed: network error while attempting to run command 'create' on host 'percona-db-psmdb-db-rs0.default.svc.cluster.local:27017' :

```

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [December 27, 2021, 11:04am UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596/2 "2021-12-27T11:04:40Z")

</div>

Hello @anon17965173 ,

thank you for raising it here.

1. will move it to operator forum.
2. what is the question here?

Are you deploying default helm chart and the cluster is not starting?  
Or are you trying to change read preference and it is not working? If it is this one - what are you trying to accomplish here?

---

<div class="post-metadata">

**Author:** ![anon17965173](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon17965173](https://forums.percona.com/u/anon17965173)\
**Post date:** [January 10, 2022, 6:43pm UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596/3 "2022-01-10T18:43:00Z")

</div>

Hi spronin and thanks for your response!

Yes, this was the default helm chart. Readme says:

`# psmdb-db: A chart for installing Percona Server MongoDB Operator managed Databases`

My question was how to troubleshoot an instable cluster. I tried nothing out of the ordinary. I redeployed, it could have been a performance, out of memory issue. For now, we can close this. Once my redeployment runs into the same issue (I hope not), I will reply to this thread.

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [January 11, 2022, 7:44am UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596/4 "2022-01-11T07:44:10Z")

</div>

Understood, so it was some glitch. Please let me know if you still have questions.

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [January 11, 2022, 7:44am UTC](https://forums.percona.com/t/could-not-find-host-matching-read-preference-mode-nearest-for-set-rs0/13596/5 "2022-01-11T07:44:16Z")

</div>


