when I use mongo shell or mongo driver to connect to a mongodb instance, how can I know whether it is a single instance, replica set or mongos etc.
isMaster
isMaster returns a document that describes the role of the mongod instance.
If the instance is a member of a replica set, then isMaster returns a subset of the replica set configuration and status including whether or not the instance is the primary of the replica set.
When sent to a mongod instance that is not a member of a replica set, isMaster returns a subset of this information.
MongoDB drivers and clients use isMaster to determine the state of the replica set members and to discover additional members of a replica set.
The db.isMaster() method in the mongo shell provides a wrapper around isMaster.
For more on the isMaster please take a look here