Panoply Blog: Data Management, Warehousing & Data Analysis

CouchDB vs MongoDB

Written by Matan Sarig | Jun 12, 2017 11:07:44 AM

Whether your database needs to run on a mobile device or scale to a humongous size, this post has you covered with CouchDB vs. MongoDB. One of these databases can run on your phone while the other is prepared for serious growth; which one do you need?

 Who Uses These Databases?

Here are a few examples of companies that use these databases:

CouchDB: Talend SA, Akamai Technologies, Hothead Games, Inc., GenCorp Technologies, Vivint Solar, Inc.

MongoDB: Adobe, BBVA, CERN, Department of Veteran Affairs, Electronic Arts, Forbes, Under Armour

 What About Database Structure?

CouchDB: CouchDB uses a document store with data being presented in the JSON format. It offers a RESTful HTTP API for reading, adding, editing, and deleting database documents. Each document consists of fields and attachments. Fields can consist of numbers, text, booleans, lists, and more.

The update model for CouchDB is optimistic and lockless. This database structure, inspired by Lotus Notes, can be scaled from global clusters down to mobile devices.

MongoDB: MongoDB stores schema-free data using documents in the BSON format. These collections of documents are not required to have a predefined structure, and columns can vary for different documents in the collection.

MongoDB is schema-free, allowing you to create documents without having to first create the structure for that document. At the same time, it still has many of the features of a relational database, including strong consistency and an expressive query language.

Are Indexes Needed?

CouchDB: Views in CouchDB are similar to indexes in SQL. Views in CouchDB can be used for filtering documents, retrieving data in a specific order, and creating efficient indexes so you can find documents using values within them. Once you have indexes, they can represent relationships between the documents. These view results are stored in a B-tree index structure.

CouchDB uses MapReduce, a two-step process that looks at all of the documents and creates a map result consisting of an ordered list of key/value pairs. The mapping occurs once after a document is created. After that, it is not changed unless the document is updated.

MongoDB: Indexes are the preferred method in MongoDB, and not having indexes can slow down read times. 

How Are Their Queries Different?

To view all documents in a database called mybooks:

CouchDB:

cURL can be used to query the database using HTTP:

curl -X GET http://127.0.0.1:5984/mybooks/_all_docs

MongoDB: db.mybooks.find( {} )

While selecting all documents is helpful, you often need to filter the result. In this case, we are going to search the database mybooks to find one with the search term “Tolstoy.”

CouchDB:

In order to look this up, we first need an index. CouchDB uses a map result to store the index.

To find the value “Tolstoy,” we need to retrieve the values in the key of a view. To do this, we use a map function:

function(doc) {

if(doc.author) {

emit(doc.author, null);

}

}

This map function will create a list of documents sorted by the author field.

To list all records that have the author “Tolstoy,” we use the following query:

curl -X GET http://127.0.0.1:5984/mybooks/_design/application/_view/author?key="Tolstoy"

MongoDB:

db.mybooks.find( { author: “Tolstoy” } )

Where (And How) Are These Databases Deployed?

CouchDB: CouchDB was written in Erlang and is available for Android, BSD, iOS, Linux, OS X, Solaris, and Windows.

It has support for many programming languages, including: C, C#, ColdFusion, Erlang, Haskell, Java, JavaScript, Lisp, Lua, Objective-C, OCaml, Perl, PHP, PL/SQL, Python, Ruby, and Smalltalk.

MongoDB: MongoDB was written in C++ and can be deployed to Linux, OS X, Solaris, and Windows.

The following programming languages are supported in MongoDB: Actionscript, C, C#, C++, Clojure, ColdFusion, D, Dart, Delphi, Erlang, Go, Groovy, Haskell, Java, JavaScript, Lisp, Lua, MatLab, Perl, PHP, PowerShell, Prolog, Python, R, Ruby, Scala, and Smalltalk.

What Types Of Replication / Clustering Are Available?

CouchDB: CouchDB supports both master-master and master-slave replication. This allows low latency access to data regardless of location. Replication in CouchDB is as simple as sending HTTP requests to the database with a source and target.

CouchDB will start sending any changes that occur in the source to the target database. This is a unidirectional process. If you want a bidirectional process, you will need to trigger the replication on the destination server with it being the source and the remote server being the destination.

MongoDB: MongoDB offers single-master replication with auto-election built-in. This will promote a secondary database (auto-election) if the primary database becomes unavailable. With replica sets in MongoDB, there can be one primary database with multiple replicated databases having the secondary role.

With Panoply, smart data warehouse you can connect to CouchDB and MongoDB databases at the same time. This allows you to access all of your data, regardless of where it is stored, from one place.

Who's Currently Behind The Databases?

CouchDB: CouchDB is currently managed by the Apache Software Foundation. It was originally created in 2005 by Damien Katz, a former IBM developer that worked on Lotus Notes.

MongoDB: MongoDB was started in 2007 by 10gen, which later changed its name to MongoDB, Inc. MongoDB, Inc. currently manages the project.

Who Provides Support?

CouchDB: The Apache Software Foundation offers community support at Slack and Freenode IRC network chat. Enterprise level support for the product is offered through professional services from companies like Neighbourhoodie Software.

MongoDB: MongoDB, Inc offers a support community via the Community Support Forum, ServerFault, and StackOverflow. Users can also get enterprise support 24x7 with optional lifecycle via Enterprise grade support.

Who Maintains The Documentation?

CouchDB: The documentation for CouchDB is maintained by the Apache Software Foundation and can be found at http://docs.couchdb.org/en/2.0.0/.

MongoDB: MongoDB, Inc. maintains the documentation for MongoDB and it can be found at https://docs.MongoDB.com/.

Is There An Active Community?

CouchDB: According to the CouchDB website, their primary goal is to “build a welcoming, supporting, inclusive and diverse community.” On the website, they offer a variety of ways people can contribute.

MongoDB: MongoDB offers an active community, which can be found at https://www.mongodb.com/community, where they offer information about events, webinars, user groups, and MongoDB University.

CouchDB vs MongoDB. Which Database Is Right For Your Business? 

 CouchDB:

Mobile support: CouchDB stands out, in that it can run on an Android or iOS mobile device. In addition to being mobile, the database can also synchronize with a remote master database, allowing the data to be shared easily between mobile devices and servers.

Snapshots: Any changes to a document occur as a revision and appends the information to the file. This means you can grab a “snapshot” of the file and copy it to another location even while the database is running without having issues with corruption.

Replication: With CouchDB, you have master-master in addition to master-slave replication. Because CouchDB only does append-only modifications to the database, it lowers the risk of conflicts. With CouchDB, you can have master-master replication where all servers are bidirectionally replicating.

You also have the ability to do selective replication where filters can control which documents will be copied onto a device. This allows a mobile device with less memory to have a subset of a database.

Queries: In CouchDB, queries use map-reduce functions which can be a difficult concept to master for people with an SQL background. However, given time you may find it a quick and elegant solution.

MongoDB:

Queries: MongoDB is closer to SQL, and as a result will probably be easier for users with SQL experience to get up to speed.

Faster reads: MongoDB provides faster reads than CouchDB as MongoDB uses a binary protocol that is faster than CouchDB’s RESTful HTTP API method.

Replication: MongoDB only offers master-slave replication across replication sets. “If you need multiple masters in a Mongo environment, you have to setup sharding in addition to replica sets and each shard will be its own replica set with the ability to write to each master in each set. Unfortunately this leads to much more complex setups and you cannot have every server have a full copy of the data set (which can be handy/critical for some geographically dispersed systems - like a CDN or DNS service),” says Riyad Kalla, Director of Global Credit Platform at PayPal.

Size: If you need to store a large or rapidly growing dataset, then MongoDB is a better choice.

With Panoply, it doesn’t matter whether you pick CouchDB or MongoDB to run your business. With it, you get a single data management solution that can connect to cloud, CouchDB, MongoDB, Redis, Cassandra etc. without a single line of code. Panoply is a smart data warehouse that automates the collection, modeling, and scaling of any data. Here is all you need to know about data warehousing and data warehouse concepts.

Want to know more about MongoDB? Check our other comparisons: MongoDB vs Redis; MongoDB vs Cassandra or MongoDB vs MySQL. Additionally, you can also learn more about how Redshift clusters work.