How we can set 2 instance of MongoDB in same machine

How we can setup 2 Nodes Mongo DB Cluster with the help of 1 Arbiter,

For example:

Node 1 : Mongodb1 (Primary)
Node 2 : Mongodb2 (Secondary) , Arbiter

(or)

Node 1 : Mongodb1 (Primary), Arbiter
Node 2 : Mongodb2 (Secondary)

MongoDB replicase set cannot be set with 2 nodes. It begins with a minimum of three nodes ( can be 3 data nodes (or) 2 data nodes + 1 arbiter )

If you still go ahead and create a 2 node cluster, then as soon as 1 data node fails, the other data node cannot serve requests as this node needs majority votes ( 2 in this case) to be a primary. So, avoid this setup

Thank you for your reply, but as per the documentation I came across that we can, have 1 primary and 1 secondary with arbiter

Please correct me, if my understanding is wrong

That is correct but colocating an arbiter on the same host as a data node is of little value.

A 3rd data node is highly recommended and an arbiter should be used as a last resort.

The 3rd node, whether an arbiter or data node, is required to help determine the next node to promote to primary in the case one goes offline or a network partition occurs…