83

I am someone new to mongoDB and has absolutely no knowledge regarding databases so would like to know what is a cluster in MongoDB and what is the point of connecting to one in MongoDB? Is it a must to connect to one or can we just connect to the localhost?

3 Answers 3

90

A mongodb cluster is the word usually used for sharded cluster in mongodb. The main purposes of a sharded mongodb are:

  • Scale reads and writes along several nodes
  • Each node does not handle the whole data so you can separate data along all the nodes of the shard. Each node is a member of a shard (which is a replicaset, see below for the explanation) and the data are separated on all shards.

This is the representation of a mongodb sharded cluster from the official doc.

mongodb sharded cluster

If you are starting with mongodb, I do not recommend you to shard your data. Shards are way more complicated to maintain and handle than replicasets are. You should have a look at a basic replicaset. It is fault tolerant and sufficient for simple needs.

The ideas of a replicaset are :

  • Every data are repartited on each node
  • Only one node accept writes

A replicaset representation from the official doc

enter image description here

For simple apps there is no problem to have your mongodb cluster on the same host than your application. You can even have them on a single member replicaset but you won't be fault tolerant anymore.

2
  • 1
    Well said but a cluster need not always be sharded. You may very have production setups to have high availability with "just" bunch of read replicas with an internal quorum. Apr 17, 2017 at 9:03
  • 1
    "Scale reads and writes along several nodes" -- this makes no sense to me, coming from a JavaScript background (haven't worked with MongoDB before). I would suggest a clearer explanation for this part.
    – nCardot
    Nov 25, 2019 at 22:11
9

Atlas-managed MongoDB deployments, or “clusters,” can be either a replica set or a sharded cluster.

replica set: a cluster of MongoDB servers that implements replication and automated failover. (Failover is a method of protecting computer systems from failure, in which standby equipment automatically takes over when the main system fails.)

replication: a feature allowing multiple database servers to share the same data, thereby ensuring redundancy and facilitating load balancing. (Redundancy is a system design in which a component is duplicated so if it fails there will be a backup.)

sharded cluster: the set of nodes comprising a sharded MongoDB deployment. A sharded cluster consists of config servers, shards, and one or more mongos routing processes.

sharding: a method for distributing data across multiple machines.

A sharded cluster consists of ten servers: one server for the mongos [interface between the client applications and the sharded cluster] and three servers each for the first replica set, the second replica set, and the config server replica set

shard: a single mongod instance or replica set that stores some portion of a sharded cluster’s total data set. In production, all shards should be replica sets.

Sources: MongoDB docs: Glossary, Create a Cluster, Convert a Replica Set to a Sharded Cluster

0
-8

It will be more clear, if you create a cluster in the cloud website of mongo. Try free version. You can see live monitoring of servers.enter image description here

1
  • 2
    This is not related to the question by any means . Jan 11, 2021 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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