Solved

MongoDb: WriteConcern

Posted on 2014-02-21
3
305 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
junit as external jar or library 7 40
What browser will run Java? 7 132
Java List 4 44
Access control a form field in Lotus Notes 3 29
Creating and Managing Databases with phpMyAdmin in cPanel.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

697 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