0

Is there a way to adjust priorities of the nodes based on hostname instead of sequence.

Using sequence -

cfg=rs.conf()
cfg.members[0].priority=100 
cfg.members[1].priority=10
cfg.members[2].priority=10
cfg.members[3].priority=0
cfg.members[4].priority=0
rs.reconfig(cfg)

What I would need is something like,

cfg=rs.conf()
cfg.members[where name like 'abc'].priority=100 
cfg.members[where name like 'pqr'].priority=10
cfg.members[where name like 'xyz'].priority=10
cfg.members[where name like '10.12.13.14'].priority=0
cfg.members[where name like '10.12.13.14'].priority=0
rs.reconfig(cfg)

Updating bulk of replica sets of different clusters would be difficulty with sequences.

Sequence of hostnames are not in ordered. So if I need to update specific host with highest priority during maintenance I cannot rely on sequence. May be using java script is easy.

0
1

Yes, you can use a Javascript like this:

cfg = rs.conf()
cfg.members.forEach(function(member) {
   if (member.host.includes("abc"))
      member.priority = 100
   else if (/xyz/.test(member.host))
      member.priority = 10
   else if (member.host == '10.12.13.14')
      member.priority = 0;
})
rs.reconfig(cfg)
2
  • another similar question if I've to get something like analogous to statement in SQL from rs.status output in mongoDB - select health from rs.status where hostname like 'abc:123' what would be the query in mongoDB ?
    – unknown
    Jul 15 at 11:32
  • Wernfried Domscheit I've posted a new question - dba.stackexchange.com/questions/295799/…
    – unknown
    Jul 19 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.