4

I have decided to start developing a little web application in my spare time so I can learn about MongoDB. I was planning to get an Amazon AWS micro instance and start the development and the alpha stage there. However, I stumbled across a question here on Stack Overflow that concerned me:

But for durability, you need to use at least 2 mongodb server instances as master/slave. Otherwise you can lose the last minute of your data.

Is that true? Can't I just have my box with everything installed on it (Apache, PHP, MongoDB) and rely on the data being correctly stored? At least, there must be a config option in MongoDB to make it behave reliably even if installed on a single box - isn't there?

Community
  • 1
  • 1
Dan
  • 15,948
  • 20
  • 63
  • 92
  • 1
    That post is outdated. MongoDB supports single-server durability since 1.8. – pingw33n May 03 '12 at 15:51
  • Thanks, pingw33n. Based on your comment, I have found this: http://thechangelog.com/post/2959787099/mongodb-1-7-5-released-single-server-durability – Dan May 03 '12 at 15:53
  • I have also added a comment to the linked article, saying that statement is outdated. Thanks! – Dan May 07 '12 at 10:45

2 Answers2

14

The information you have on master/slave setups is outdated. Running single-server MongoDB with journaling is a durable data store, so for use cases where you don't need replica sets or if you're in development stage, then journaling will work well.

However if you're in production, we recommend using replica sets. For the bare minimum set up, you would ideally run three (or more) instances of mongod, a 'primary' which receives reads and writes, a 'secondary' to which the writes from the primary are replicated, and an arbiter, a single instance of mongod that allows a vote to take place should the primary become unavailable. This 'automatic failover' means that, should your primary be unable to receive writes from your application at a given time, the secondary will become the primary and take over receiving data from your app.

You can read more about journaling here and replication here, and you should definitely familiarize yourself with the documentation in general in order to get a better sense of what MongoDB is all about.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
Barrie
  • 811
  • 6
  • 6
  • Thanks Barrie for your nice and satisfactory answer. Looking forward to learning more about MongoDB! – Dan May 03 '12 at 16:20
0

Replication provides redundancy and increases data availability. With multiple copies of data on different database servers, replication protects a database from the loss of a single server. Replication also allows you to recover from hardware failure and service interruptions. With additional copies of the data, you can dedicate one to disaster recovery, reporting, or backup.

In some cases, you can use replication to increase read capacity. Clients have the ability to send read and write operations to different servers. You can also maintain copies in different data centers to increase the locality and availability of data for distributed applications. Replication in MongoDB

A replica set is a group of mongod instances that host the same data set. One mongod, the primary, receives all write operations. All other instances, secondaries, apply operations from the primary so that they have the same data set.

The primary accepts all write operations from clients. Replica set can have only one primary. Because only one member can accept write operations, replica sets provide strict consistency. To support replication, the primary logs all changes to its data sets in its oplog. See primary for more information.

Diwakar upadhyay
  • 434
  • 5
  • 14