0
0
MongoDBquery~10 mins

Replica set architecture mental model in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find the primary node in a MongoDB replica set.

MongoDB
rs.status().members.find(member => member.stateStr === [1])
Drag options to blanks, or click blank then click option'
A"SECONDARY"
B"PRIMARY"
C"ARBITER"
D"HIDDEN"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing "SECONDARY" which only replicates data but does not accept writes.
Confusing "ARBITER" with primary; arbiters do not hold data.
2fill in blank
medium

Complete the command to add a new member to the replica set configuration.

MongoDB
cfg.members.push({ _id: 2, host: [1] }); rs.reconfig(cfg)
Drag options to blanks, or click blank then click option'
A"localhost:27020"
B"localhost:27017"
C"localhost:27019"
D"localhost:27018"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same port as the primary node (27017), causing conflicts.
Forgetting to call rs.reconfig after modifying the configuration.
3fill in blank
hard

Fix the error in the command to check the replica set status.

MongoDB
rs.[1]()
Drag options to blanks, or click blank then click option'
Astatus
Bstat
Cstate
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stat' or 'state' which are not valid rs commands.
Trying 'info' which does not exist in the rs object.
4fill in blank
hard

Fill both blanks to create a query that reads from secondary members only.

MongoDB
db.getMongo().setReadPref({ mode: [1], tags: [2] })
Drag options to blanks, or click blank then click option'
A"secondary"
B"primary"
C{}
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Setting mode to "primary" which reads only from the primary node.
Using null for tags which may cause errors.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps member hosts to their states for members in the replica set.

MongoDB
const memberStates = rs.status().members.reduce((acc, [3]) => { acc[[1]] = [2]; return acc; }, {})
Drag options to blanks, or click blank then click option'
Amember.host
Bmember.stateStr
Cmember
Dmembers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'members' instead of 'member' in the loop variable.
Swapping key and value positions.