ChatGPT解决这个技术问题 Extra ChatGPT

When to use CouchDB over MongoDB and vice versa

I am stuck between these two NoSQL databases.

In my project I will be creating a database within a database. For example, I need a solution to create dynamic tables.

So users can create tables with columns and rows. I think either MongoDB or CouchDB will be good for this, but I am not sure which one. I will also need efficient paging as well.

I wish they would modify the system to better facilitate creation of the on-topic question they are looking for, and to better direct users to that question. I have no idea if this question was ever addressed and no convenient way to track it down.
I wish they will add the functionality in this website where we could "upvote" or "downvote" the reason itself given to this question as "off-topic" which might help turning these type of questions back to "on topic".
++ It not clear to me why this is off-topic. The question does have clear objective answers -- the OP is not asking for opinion but for objective information about these two systems. user799188 provided a great objective answer.
I guess admins just look at the question if it contains any piece of code and not at the kind of information being sought.. Btw you can always vote to reopen the question.
The question just re-opened. Welcome back, everyone...

F
Flimzy

Of C, A & P (Consistency, Availability & Partition tolerance) which 2 are more important to you? Quick reference, the Visual Guide To NoSQL Systems

MongodB : Consistency and Partition Tolerance

CouchDB : Availability and Partition Tolerance

A blog post, Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase vs Membase vs Neo4j comparison has 'Best used' scenarios for each NoSQL database compared. Quoting the link,

MongoDB: If you need dynamic queries. If you prefer to define indexes, not map/reduce functions. If you need good performance on a big DB. If you wanted CouchDB, but your data changes too much, filling up disks.

CouchDB : For accumulating, occasionally changing data, on which pre-defined queries are to be run. Places where versioning is important.

A recent (Feb 2012) and more comprehensive comparison by Riyad Kalla,

MongoDB : Master-Slave Replication ONLY

CouchDB : Master-Master Replication

A blog post (Oct 2011) by someone who tried both, A MongoDB Guy Learns CouchDB commented on the CouchDB's paging being not as useful.

A dated (Jun 2009) benchmark by Kristina Chodorow (part of team behind MongoDB),

I'd go for MongoDB.

Hope it helps.


From what I understand MongoDB is not consistent in any way: ivoras.sharanet.org/blog/tree/…
Good info for the time, but this is really old... lots has changed (including REST interfaces for Mongo).
I think it might be a bit misleading, but versioning in couchdb isn't an argument. The versioning scheme used by couchdb shouldn't be used as versioning per say. It is used to handle partitions. During a database compaction, revisions will get deleted as in really deleted. And only the rev chains should remain in the database. If you want to handle versions in couchdb it should be done just as it could be done in mongodb.
I'd add to the list that couchdb can have self contained web applications. As in couchdb is in fact a webserver.
I am surprised 332 votes for a wrong answer. MongoDB is CP by default and CouchDB is AP stackoverflow.com/questions/11292215/…
E
Ewan Makepeace

The answers above all over complicate the story.

If you plan to have a mobile component, or need desktop users to work offline and then sync their work to a server you need CouchDB. If your code will run only on the server then go with MongoDB

That's it. Unless you need CouchDB's (awesome) ability to replicate to mobile and desktop devices, MongoDB has the performance, community and tooling advantage at present.


"lol how little is your data?" - is that really a thing? I might choose CDB because my data is large - or I might choose it because it has better replication than the alternatives. In this case we filter datasets down to about 100Mb-200Mb per device. Is that a bad thing?
If your code will only run on one server. Sorting out a highly-available system is a lot easier with multi-master replication.
I agree with this answer. #1 is why I chose to use CouchDB and I've not regretted it. It was probably easier for me than those coming from a SQL background because I never used SQL for my web apps. Using PouchDB.js on the client side of your app will make using CouchDB much easier. You can find it at pouchdb.com.
@Daniel W. You know filtered replication is a thing right?
t
tobiak777

Very old question but it's on top of Google and I don't quite like the answers I see so here's my own.

There's much more to Couchdb than the ability to develop CouchApps. Most people use CouchDb in a classical 3-tiers web architecture.

In practice the deciding factor for most people will be the fact that MongoDb allows ad-hoc querying with a SQL like syntax while CouchDb doesn't (you've got to create map/reduce views which turns some people off even though creating these views is Rapid Application Development friendly - they have nothing to do with stored procedures).

To address points raised in the accepted answer : CouchDb has a great versionning system, but it doesn't mean that it is only suited (or more suited) for places where versionning is important. Also, couchdb is heavy-write friendly thanks to its append-only nature (writes operations return in no time while guaranteeing that no data will ever be lost).

One very important thing that is not mentioned by anyone is the fact that CouchDb relies on b-tree indexes. This means that whether you have 1 "row" or 20 billions, the querying time will always remain below 10ms. This is a game changer which makes CouchDb a low-latency and read-friendly database, and this really shouldn't be overlooked.

To be fair and exhaustive the advantage MongoDb has over CouchDb is tooling and marketing. They have first-class citizen tools for all major languages and platforms making the on-boarding easy and this added to their adhoc querying makes the transition from SQL even easier.

CouchDb doesn't have this level of tooling - even though there are many libraries available today - but CouchDb is exposed as an HTTP API and it is therefore quite easy to create a wrapper in your favorite language to talk with it. I personally like this approach as it avoids bloat and allows you to only take what you want (interface segregation principle).

So I'd say using one or the other is largely a matter of comfort and preference with their paradigms. CouchDb approach "just fits", for certain people, but if after learning about the database features (in the exhaustive official guide) you don't have your "hell yeah" moment, you should probably move on.

I'd discourage using CouchDb if you just want to use "the right tool for the right job". because you'll find out that you can't just use it that way and you'll end up being pissed and writing blog posts such as "Where are joins in CouchDb ?" and "Where is transaction management ?". Indeed Couchdb is - paradoxically - very transparent but at the same time requires a paradigm shift and a change in the way you approach problems to really shine (and really work).

But once you've done that it really pays off. I'd personally need very strong reasons or a major deal breaker on a project to choose another database, but so far I haven't met any.


Update 2016 : Since version 2.0 released in september 2016, CouchDb is supporting ad-hoc queries out-of-the-box :)
CouchDb relies on b-tree indexes. This means that whether you have 1 "row" or 20 billions, the querying time will always remain below 10ms. Isn't this true of nearly all databases? This way this is phrased implies otherwise.
@Shelvacu Indeed you make a point, what is special with CouchDB with this regard is that when using Map/Reduce, you can be sure that all your queries will always use pre-computed and incremental indexes (while with other databases, the query planner may choose not use any index, or the developer may have poorly written a query or made a mistake causing a query to do table scans). By contrast, with CouchDB all queries always leverage a pre-computed b-tree index with CouchDB Map/reduce, which makes them very fast.
However if you use the ad-hoc querying style introduced in CouchDB 2.0 (called Mango) the behavior is less predictable and some filtering may take place in-memory if you use certain operators in your queries. This is the reason I personally prefer to always use Map/Reduce as this gives me the guarantee that all queries will be answered using the pre-computed b-tree for top performance. The pre-computed, incremental and very predictable nature of CouchDb queries is one of its major benefits.
m
marc_s

Ask this questions yourself? And you will decide your DB selection.

Do you need master-master? Then CouchDB. Mainly CouchDB supports master-master replication which anticipates nodes being disconnected for long periods of time. MongoDB would not do well in that environment. Do you need MAXIMUM R/W throughput? Then MongoDB Do you need ultimate single-server durability because you are only going to have a single DB server? Then CouchDB. Are you storing a MASSIVE data set that needs sharding while maintaining insane throughput? Then MongoDB. Do you need strong consistency of data? Then MongoDB. Do you need high availability of database? Then CouchDB. Are you hoping multi databases and multi tables/ collections? Then MongoDB You have a mobile app offline users and want to sync their activity data to a server? Then you need CouchDB. Do you need large variety of querying engine? Then MongoDB Do you need large community to be using DB? Then MongoDB


#9 is a virtual tie between CouchDB and MongoDB as of CouchDB 2.x.
A
Alexis Dufrenoy

I summarize the answers found in that article:

http://www.quora.com/How-does-MongoDB-compare-to-CouchDB-What-are-the-advantages-and-disadvantages-of-each

MongoDB: Better querying, data storage in BSON (faster access), better data consistency, multiple collections

CouchDB: Better replication, with master to master replication and conflict resolution, data storage in JSON (human-readable, better access through REST services), querying through map-reduce.

So in conclusion, MongoDB is faster, CouchDB is safer.

Also: http://nosql.mypopescu.com/post/298557551/couchdb-vs-mongodb


m
mark

Be aware of an issue with sparse unique indexes in MongoDB. I've hit it and it is extremely cumbersome to workaround.

The problem is this - you have a field, which is unique if present and you wish to find all the objects where the field is absent. The way sparse unique indexes are implemented in Mongo is that objects where that field is missing are not in the index at all - they cannot be retrieved by a query on that field - {$exists: false} just does not work.

The only workaround I have come up with is having a special null family of values, where an empty value is translated to a special prefix (like null:) concatenated to a uuid. This is a real headache, because one has to take care of transforming to/from the empty values when writing/quering/reading. A major nuisance.

I have never used server side javascript execution in MongoDB (it is not advised anyway) and their map/reduce has awful performance when there is just one Mongo node. Because of all these reasons I am now considering to check out CouchDB, maybe it fits more to my particular scenario.

BTW, if anyone knows the link to the respective Mongo issue describing the sparse unique index problem - please share.


Indeed you should. Consider an entity describing a corporation. It must have a unique business number and may have a business name, which if present must be unique. The example is somewhat simplified, but it is not far fetched.
Another example of sparse unique indexes could be a client table with a national id number field which by definition is unique - but can be unknown (perhaps the client is a foreigner).
The point is there are real uses for this concept and MongoDB just does not do it right.
Mongo's Aggregation framework (in version 2.4.8) works much nicer than their map-reduce and, in my opinion, easier to use and wrap your head around (I'm sure that's not the case if you're used to map-reduce, I just took the mongodb class and the aggregation framework was very flexible). The soon to be released 2.6.8 will return aggregation results as a cursor rather than a document, removing the memory limits previously applied to mapresult and aggregation calls.
@mark I know this probably isn't very satisfying, but with a little trickery and tom-foolery (which already feels bad to MY gut), you can have indexes that satisfy both. You have your existing sparse, unique index. Then make another index that's not unique or sparse, but add another field to the index (after the field in question). Then you can use query hints to force the optimizer to pick the correct index (when I tested this, I needed to force the hint on the sparse, unique index to find exact matches/ranges, but didn't need the hint for finding {$exists: false}).
d
dm.

I'm sure you can with Mongo (more familiar with it), and pretty sure you can with couch too.

Both are documented oriented (JSON-based) so there would be no "columns" but rather fields in documents -- but they can be fully dynamic.

They both do it you may want to look at other factors on which to use: other features you care about, popularity, etc. Google insights, indeed.com job posts would be ways to look at popularity.

You could just try it i think you should be able to have mongo running in 5 minutes.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now