Complete the code to find the primary node in a MongoDB replica set.
rs.status().members.find(member => member.stateStr === [1])The primary node is the one with stateStr equal to "PRIMARY" in the replica set status.
Complete the command to add a new member to the replica set configuration.
cfg.members.push({ _id: 2, host: [1] }); rs.reconfig(cfg)When adding a new member, specify its host and port correctly. Here, port 27018 is used as an example for the new member.
Fix the error in the command to check the replica set status.
rs.[1]()The correct command to check the replica set status is rs.status(). Other options are invalid commands.
Fill both blanks to create a query that reads from secondary members only.
db.getMongo().setReadPref({ mode: [1], tags: [2] })To read from secondary members, set the read preference mode to "secondary" and use an empty tags object {} to include all secondaries.
Fill all three blanks to create a dictionary comprehension that maps member hosts to their states for members in the replica set.
const memberStates = rs.status().members.reduce((acc, [3]) => { acc[[1]] = [2]; return acc; }, {})
This expression creates an object mapping each member's host to its state string by iterating over each member.