Solved

MongoDb: WriteConcern

Posted on 2014-02-21
3
309 Views
Last Modified: 2016-02-10
Hi there,

I am using mongodb client for java and I want it to be efficient.

Which "WriteConcern" is most efficient to be used?

Any help is greatly appreciated. I have done programming but it is my first time using mongodb.

Thanks,
Zizi
0
Comment
Question by:zizi21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 300 total points
ID: 39879604
I've not personally used Mongo but I understand its design.  As you raise the strength (level) of WriteConcern you will get less efficiency but more guarantees that the write has completed.

For low level settings like "Unacknowledged" you'll get a really fast response, but there's no guarantee that the data has been reliably written.  So if you had a server crash you might not be able to recover that write.  This may or may not be OK.

Up at the high end like "Replica Acknowledged" your writes will wait until Mongo has successfully heard back from other servers indicating that the write has propagated.  You can be sure that data won't be lost even after a server crash here.  But it will be significantly slower as you are waiting for those replicating servers to receive the data and respond back.

Hope that helps,

Doug
0
 
LVL 11

Assisted Solution

by:anilallewar
anilallewar earned 200 total points
ID: 39879865
It depends on what your use case is :)

The default write concern is acknowledged which means that the server was able to successfully write your entry and there is no error but it is not going to wait for journaling or replication confirmation.

IMHO this is the most efficient writeconcern that would also give you enough consistency so that you know that your writes made their way to the primary node.

As Doug said if you really concerned about the speed of writes, you can go with un-acknowleged writes but you would not know if the last write failed.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 40090053
Hi, zizi21.

I know, it's too late for comments, but you may read this blog post with benchmark results and good recommendations in write-mostly scenario.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question