Вопрос

I have replication set up (localhost:27017(primary),localhost:27018(secondary),localhost:27019(arb))

I have set the readPrefrence as secondary in connection lever like below mongoInstance.setReadPreference(ReadPreference.secondary());

When i save some data through this connection will request rout to primary?

how do i confirm this?

I have seen DBCollection coll = getCollection();

         coll.getStats();
enter code here

In this "serverUsed":"localhost:27018" has shown.

Это было полезно?

Решение

No. As the term says, readPreference only sets the preferred server to read from in the cluster. You can only write to primary servers in a replica set.

Другие советы

It doesn't read from a primary, read preference secondary means exactly this, it doesn't disturb primary ever.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top