Replication write operation break when Primary node is down

I have PSS Cluster . i am tying to run query like
db.collection.aggreagate([{$out:“test”}]).
when primary node is down its give me error like ->
Not primary while writing to ‘PERFORMANCE.collection’ on server.
i do not want to run manually that command .
Is there any configuration. when primary goes down secondary become a primary and automatically completed that task(currently i have to run manually that command when election is completed and secondary node become primary)

It is automatic if you connect to the cluster rather than connecting to a specific host.

Which connection string did you use?

1 Like

<Resource name=“mongodb/mongoClient” auth=“Container”
type=“com.mongodb.MongoClient”
closeMethod=“close”
factory=“com.greenlight.platform.dao.configuration.CustomMongoClientJNDIFactory”
singleton=“true”
connectionString =mongodb://admin:b0wshghshn789@abch:10200,xxxx:10006,yyyy:10007/PERFORMANCE?replicaSet=HReplSet;readPreference=secondaryPreferred;authMechanism=SCRAM-SHA-1" />

<Resource name=“mongodb/mongoClientPrimary” auth=“Container”
type=“com.mongodb.MongoClient”
closeMethod=“close”
factory=“com.greenlight.platform.dao.configuration.CustomMongoClientJNDIFactory”
singleton=“true”
connectionString =“mongodb://admin:b0689ba7a2faca1a0429234c49e@abcd10006.group.net:10200,abcde10007.group.net:10200,abcdtgroup.net:10200/PERFORMANCE?replicaSet=HReplSet;readPreference=primary;authMechanism=SCRAM-SHA-1” />

I do not recognize any of this as being an exercise or a lab from course M103.

What lab and what course are you trying to accomplish?

You should try MongoDB Developer Community Forums if your question is not related to MongoDB university offering.