Q: Mongo nodejs replicaset big query optimisation I have a nodejs app connected to a mongodb database (1 master 2 slaves)
The app is working great, each hour there is a script running taking a lot of resources on mongodb.
I do not really know if this is normal but seems that each query is going through the master then I do not know what mongo is doing internally but when the script is running mongo master slave is becoming crazy and the other do not move
This is the status of my replica set
{
        "set" : "rs0",
        "date" : ISODate("2020-09-17T08:29:22.555Z"),
        "myState" : 1,
        "term" : NumberLong(91),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1600331354, 1),
                        "t" : NumberLong(91)
                },
                "lastCommittedWallTime" : ISODate("2020-09-17T08:29:14.201Z"),
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1600331354, 1),
                        "t" : NumberLong(91)
                },
                "readConcernMajorityWallTime" : ISODate("2020-09-17T08:29:14.201Z"),
                "appliedOpTime" : {
                        "ts" : Timestamp(1600331354, 1),
                        "t" : NumberLong(91)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1600331354, 1),
                        "t" : NumberLong(91)
                },
                "lastAppliedWallTime" : ISODate("2020-09-17T08:29:14.201Z"),
                "lastDurableWallTime" : ISODate("2020-09-17T08:29:14.201Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1600331354, 1),
        "lastStableCheckpointTimestamp" : Timestamp(1600331354, 1),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "stepUpRequestSkipDryRun",
                "lastElectionDate" : ISODate("2020-08-28T16:55:35.926Z"),
                "electionTerm" : NumberLong(91),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(1598633735, 1),
                        "t" : NumberLong(90)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1598633735, 1),
                        "t" : NumberLong(90)
                },
                "numVotesNeeded" : 2,
                "priorityAtElection" : 1,
                "electionTimeoutMillis" : NumberLong(10000),
                "priorPrimaryMemberId" : 0,
                "numCatchUpOps" : NumberLong(0),
                "newTermStartDate" : ISODate("2020-08-28T16:55:35.931Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2020-08-28T16:55:38.029Z")
        },
        "electionParticipantMetrics" : {
                "votedForCandidate" : true,
                "electionTerm" : NumberLong(90),
                "lastVoteDate" : ISODate("2020-08-22T21:11:10.366Z"),
                "electionCandidateMemberId" : 0,
                "voteReason" : "",
                "lastAppliedOpTimeAtElection" : {
                        "ts" : Timestamp(1598129847, 1),
                        "t" : NumberLong(89)
                },
                "maxAppliedOpTimeInSet" : {
                        "ts" : Timestamp(1598129847, 1),
                        "t" : NumberLong(89)
                },
                "priorityAtElection" : 1
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "mongo-1.mongo.live.svc.cluster.local:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 1697606,
                        "optime" : {
                                "ts" : Timestamp(1600331354, 1),
                                "t" : NumberLong(91)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1600331354, 1),
                                "t" : NumberLong(91)
                        },
                        "optimeDate" : ISODate("2020-09-17T08:29:14Z"),
                        "optimeDurableDate" : ISODate("2020-09-17T08:29:14Z"),
                        "lastHeartbeat" : ISODate("2020-09-17T08:29:22.026Z"),
                        "lastHeartbeatRecv" : ISODate("2020-09-17T08:29:21.990Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "mongo-2.mongo.live.svc.cluster.local:27017",
                        "syncSourceHost" : "mongo-2.mongo.live.svc.cluster.local:27017",
                        "syncSourceId" : 1,
                        "infoMessage" : "",
                        "configVersion" : 7810311
                },
                {
                        "_id" : 1,
                        "name" : "mongo-2.mongo.live.svc.cluster.local:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 2200677,
                        "optime" : {
                                "ts" : Timestamp(1600331354, 1),
                                "t" : NumberLong(91)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1600331354, 1),
                                "t" : NumberLong(91)
                        },
                        "optimeDate" : ISODate("2020-09-17T08:29:14Z"),
                        "optimeDurableDate" : ISODate("2020-09-17T08:29:14Z"),
                        "lastHeartbeat" : ISODate("2020-09-17T08:29:21.291Z"),
                        "lastHeartbeatRecv" : ISODate("2020-09-17T08:29:22.033Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "mongo-0.mongo.live.svc.cluster.local:27017",
                        "syncSourceHost" : "mongo-0.mongo.live.svc.cluster.local:27017",
                        "syncSourceId" : 3,
                        "infoMessage" : "",
                        "configVersion" : 7810311
                },
                {
                        "_id" : 3,
                        "name" : "mongo-0.mongo.live.svc.cluster.local:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 2200701,
                        "optime" : {
                                "ts" : Timestamp(1600331354, 1),
                                "t" : NumberLong(91)
                        },
                        "optimeDate" : ISODate("2020-09-17T08:29:14Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1598633735, 2),
                        "electionDate" : ISODate("2020-08-28T16:55:35Z"),
                        "configVersion" : 7810311,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                }
        ],
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1600331354, 1),
                "signature" : {
                        "hash" : BinData(0,"viqVgd9SZDI2Q3NB0sz5lJo4xBM="),
                        "keyId" : NumberLong("6834562805081833474")
                }
        },
        "operationTime" : Timestamp(1600331354, 1)
}

I am connection mongo with MongoClient.connect
and the url is mongodb://username:password@mongo-0.mongo.live.svc.cluster.local:27017,mongo-1.mongo.live.svc.cluster.local:27017,mongo-2.mongo.live.svc.cluster.local:27017/admin?authSource=admin&replicaSet=rs0&slaveOk=true
Can you please let me know if my replica and connection is normal.
I do not understand why only master cpu is going up
An other solution could be to add a new master only for my script, is it a good approach ?

A: @prasad_ Thanks for the help
readPreference=secondaryPreferred to my connection url and now the read request are dispatched between my two secondary
