Question on HW- 2.1&2.2

Although I completed these homework tasks, I still have a question.

This is what I get when running rs.isMaster() after all is done :

MongoDB Enterprise HW-2.2:PRIMARY>
MongoDB Enterprise HW-2.2:PRIMARY> rs.isMaster()
{
“hosts” : [
“database:31220”,
“database.m310.mongodb.university:31221”,
“database.m310.mongodb.university:31222”
],
“setName” : “HW-2.2”,
“setVersion” : 3,
“ismaster” : true,
“secondary” : false,
“primary” : “database:31220”,
“me” : “database:31220”,
“electionId” : ObjectId(“7fffffff0000000000000001”),
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 1000,
“localTime” : ISODate(“2020-11-29T08:41:21.617Z”),
“maxWireVersion” : 4,
“minWireVersion” : 0,
“ok” : 1
}
MongoDB Enterprise HW-2.2:PRIMARY>

Notice the way the first element appears in the list of hosts.

This is the case when rs.initiate() is run this way:

MongoDB Enterprise …> rs.initiate()

I know by experience that using this other form:

rs.initiate({_id: ‘HW-2.2’,
members: [
{_id:1, host: ‘database.m310.mongodb.university:31220’}
]
})

would have produced a more homogeneous list of hosts.
This is actually what I did for HW-2.1.

It would be nice if someone could explain exactly why this is happening.

When you run rs.initiate() without params it will choose default values and hostname is one such value
On database box hostname is database
You can verify running the command hostname
You can also use rs.initiate(cfg) and rs.recconfig(cfg)
where cfg=rs.conf() and you can define values like members,priority etc
Also check this