MongoDB (from "humongous") is a cross-platform document-oriented database system. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas
Introduction
In this article we will learn about Replica set in mongoDB.we
will also see about primary ,secondary and arbiter databases in mongo db
Previous articles have provided an introduction to mongodb, setup and
installation,and few command line options.You can get them from the following:
Objective
The objective of the article is to learn about replica set in
Mongo database.Sometimes things don't always go our way...sometimes our server may crash and
when that happens...what happens to our application??
If we have a backup we will spend some time and will restore the
data which is a traditional way of doing.......
But we can do much better than that where the replica set of mongo
dB comes into role.........
Replica set
Mongo dB
supports an arrangement called a replica set, the members of replica set are
primary ,secondary or number of secondary’s and potentially an arbitrary. Let’s
look at the rows of each one of those in a replica set.
The primary database is the one and only writable instance in a replica set
that means any of the clients that want to write data to the database have to
be connected to the primary and have to issue write commands against the primary,
An attempt to write to secondary will fail...
The secondary databases are read only instances…we can have many number of
secondary databases this means that we also have scalability because we can
perform many more reads against the replicas rather than attacking a single
server with all requests for crud operations..
In the
secondary databases the data is gonna be replicated from the primary eventually
which we call eventual consistency. At some point, if primary database is
failed one of the secondary will take over and will become the primary where we
can get automatic recovery from the crash of the primary…..
The third
type of member in replica set is the arbiter. Arbiters are mongod instances
that are part of replica set but do not hold data. Arbiters participate in
elections in order to break ties. If a replica set has an even number of
members, add an arbiter.
Arbiters
have minimal resource requirements and do not require dedicated hardware. We
can deploy an arbiter on an application server, monitoring host.
Now lets create the databases and see them in action..
Here we gonna create three directories in our dotnetfunda directory named db1,db2,db3
md \dotnetfunda\db1
md \dotnetfunda\db2
md \dotnetfunda\db3
now lets start the three instances give the command
@REM Primary
start "a" mongod --dbpath .db1 --port 30000 --replSet "demo"
@REM Secondary
start "b" mongod --dbpath .db2 --port 40000 --replSet "demo"
@REM Arbiter
start "c" mongod --dbpath.db3 --port 50000 --replSet "demo"
Conclusion
In this article we have learned about replica set and we have started the overview with an example.
Reference
http://en.wikipedia.org/wiki/MongoDB
http://www.mongodb.org/