Comparing Mongo DB and Couch DB

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介:

http://www.mongodb.org/display/DOCS/Comparing+Mongo+DB+and+Couch+DB, 英文

http://www.searchdatabase.com.cn/showcontent_46595.htm, 中文

 

最根本的不同是, 应用场景的不同, 是对CAP的取舍的不同

MongoDB选择牺牲可用性来保证一致性和原子性, 而couchDB却是选择放弃一致性而保持高可用性, 所以CouchDB更像KV,nosql, 而MongoDB太象关系型数据库

 

We are getting a lot of questions "how are mongo db and couch different?"  It's a good question: both are document-oriented databases with schemaless JSON-style object data storage.  Both products have their place -- we are big believers that databases are specializing and "one size fits all" no longer applies.

We are not CouchDB gurus so please let us know in the forums if we have something wrong.

 

MVCC

One big difference is that CouchDB is MVCC  based, and MongoDB is more of a traditional update-in-place store.  
MVCC is very good for certain classes of problems:

    • problems which need intense versioning;
    • problems with offline databases that resync later;
    • problems where you want a large amount of master-master replication happening.

Along with MVCC comes some work too:

    • first, the database must be compacted periodically, if there are many updates. 
    • Second, when conflicts occur on transactions, they must be handled by the programmer manually (unless the db also does conventional locking -- although then master-master replication is likely lost).

MongoDB updates an object in-place when possible.  Problems requiring high update rates of objects are a great fit; compaction is not necessary. Mongo's replication works great but, without the MVCC model, it is more oriented towards master/slave and auto failover configurations than to complex master-master setups.  With MongoDB you should see high write performance, especially for updates.

这个应该是最大的区别, MongoDB采用和传统DB类似的策略, update in-place, master/slave, auto failover. MongoDB的特点就是效率高, 尤其是update

而CouchDB就采用比较少见的, append-only方式, 可以支持, MVCC, master/master, 支持offline操作.

 

Horizontal Scalability

One fundamental difference is that a number of Couch users use replication as a way to scale

With Mongo, we tend to think of replication as a way to gain reliability/failover rather than scalability.  Mongo uses (auto) sharding as our path to scalabity (sharding is GA as of 1.6).  In this sense MongoDB is more like Google BigTable.  (We hear that Couch might one day add partitioning too.)

这个也是CouchDB的一大弱点, 我不认为replication能算水平扩展的方法, 如果不支持partition的话...

 

Query Expression

Couch uses a clever index building scheme to generate indexes which support particular queries.  There is an elegance to the approach, although one must predeclare these structures for each query one wants to execute.  One can think of them as materialized views.

Mongo uses traditional dynamic queries.  As with, say, MySQL, we can do queries where an index does not exist, or where an index is helpful but only partially so.  Mongo includes a query optimizer which makes these determinations.  We find this is very nice for inspecting the data administratively, and this method is also good when we don't want an index: such as insert-intensive collections.  When an index corresponds perfectly to the query, the Couch and Mongo approaches are then conceptually similar.  We find expressing queries as JSON-style objects in MongoDB to be quick and painless though.

Update Aug2011: Couch is adding a new query language "UNQL".

MongoDB 与传统的数据库系统类似,支持动态查询,即使在没有建立索引的行上,也能进行任意的查询。而 CouchDB 不同,CouchDB 不支持动态查询,你必须为你的每一个查询模式建立相应的view,并在此view的基础上进行查询.

 

Atomicity

Both MongoDB and CouchDB support concurrent modifications of single documents.  Both forego complex transactions involving large numbers of objects.

都支持原子性修改.

 

Durability

CouchDB is a "crash-only" design where the db can terminate at any time and remain consistent.

Previous versions of MongoDB used a storage engine that would require a repairDatabase() operation when starting up after a hard crash (similar to MySQL's MyISAM). Version 1.7.5 and higher offer durability via journaling; specify the --journalcommand line option

CouchDB是append-only, 再加上两步commit, 可以保证数据的一致性, crash只会导致新数据的丢失, 而不会导致老数据的不一致.

MongoDB就和传统数据库一样, crash必然会导致数据不一致, 需要去repair

 

Map Reduce

Both CouchDB and MongoDB support map/reduce operations.  For CouchDB map/reduce is inherent to the building of all views.  With MongoDB, map/reduce is only for data processing jobs but not for traditional queries.

CouchDB的map/reduce只是用于单节点的view查询, 相当的水

而MongoDB, 用于多shard的数据统计, 相对靠谱一些

 

Javascript

Both CouchDB and MongoDB make use of Javascript.  CouchDB uses Javascript extensively including in the building of views .

MongoDB supports the use of Javascript but more as an adjunct.  In MongoDB, query expressions are typically expressed as JSON-style query objects; however one may also specify a javascript expression as part of the query.  MongoDB also supports running arbitrary javascript functions server-side and uses javascript for map/reduce operations.

简单的说, 就是用在不同的地方

 

REST

Couch uses REST as its interface to the database.  With its focus on performance, MongoDB relies on language-specific database drivers for access to the database over a custom binary protocol.  Of course, one could add a REST interface atop an existing MongoDB driver at any time -- that would be a very nice community project.  Some early stage REST implementations exist for MongoDB.

 

Performance

Philosophically, Mongo is very oriented toward performance, at the expense of features that would impede performance.  We see Mongo DB being useful for many problems where databases have not been used in the past because databases are too "heavy".  Features that give MongoDB good performance are:

  • client driver per language: native socket protocol for client/server interface (not REST)
  • use of memory mapped files for data storage, 所以非常耗内存
  • collection-oriented storage (objects from the same collection are stored contiguously)
  • update-in-place (not MVCC)
  • written in C++

 

Use Cases

It may be helpful to look at some particular problems and consider how we could solve them.

  • if we were building Lotus Notes, we would use Couch as its programmer versioning reconciliation/MVCC model fits perfectly.  Any problem where data is offline for hours then back online would fit this.  In general, if we need severaleventually consistent master-master replica databases, geographically distributed, often offline, we would use Couch.
  • mobile
    • Couch is better as a mobile embedded database on phones, primarily because of its online/offine replication/sync capabilities.
    • we like Mongo server-side; one reason is its geospatial indexes.
  • if we had very high performance requirements we would use Mongo.  For example, web site user profile object storage and caching of data from other sources.
  • for a problem with very high update rates, we would use Mongo as it is good at that because of its "update-in-place" design.  For example see updating real time analytics counters
  • in contrast to the above, couch is better when lots of snapshotting is a requirement because of its MVCC design.

Generally, we find MongoDB to be a very good fit for building web infrastructure.


本文章摘自博客园,原文发布日期:2012-07-02

相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
存储 SQL JSON
「文档数据库之争」MongoDB和CouchDB的比较
「文档数据库之争」MongoDB和CouchDB的比较
|
存储 JSON NoSQL
「文档数据库迁移」从MongoDB迁移到Apache CouchDB
「文档数据库迁移」从MongoDB迁移到Apache CouchDB
|
NoSQL 关系型数据库 数据库
数据库应用(Mysql、Mongodb、Redis、Memcached、CouchDB、Cassandra)
目前,主流数据库包括关系型(SQL)和非关系型(NoSQL)两种。 关系数据库是建立在关系模型基础上的数据库,借助于集合代数等数学概念和方法来处理数据库中的数据,支持复杂的事物处理和结构化查询。代表实现有MySQL、Oracle、PostGreSQL、MariaDB、SQLServer等。
1366 0
|
1月前
|
存储 关系型数据库 MySQL
一个项目用5款数据库?MySQL、PostgreSQL、ClickHouse、MongoDB区别,适用场景
一个项目用5款数据库?MySQL、PostgreSQL、ClickHouse、MongoDB——特点、性能、扩展性、安全性、适用场景比较
|
2月前
|
存储 NoSQL 关系型数据库
非关系型数据库-MongoDB技术(二)
非关系型数据库-MongoDB技术(二)
|
2月前
|
NoSQL 关系型数据库 MongoDB
非关系型数据库-MongoDB技术(一)
非关系型数据库-MongoDB技术(一)
|
12天前
|
NoSQL Cloud Native atlas
探索云原生数据库:MongoDB Atlas 的实践与思考
【10月更文挑战第21天】本文探讨了MongoDB Atlas的核心特性、实践应用及对云原生数据库未来的思考。MongoDB Atlas作为MongoDB的云原生版本,提供全球分布式、完全托管、弹性伸缩和安全合规等优势,支持快速部署、数据全球化、自动化运维和灵活定价。文章还讨论了云原生数据库的未来趋势,如架构灵活性、智能化运维和混合云支持,并分享了实施MongoDB Atlas的最佳实践。
|
13天前
|
NoSQL Cloud Native atlas
探索云原生数据库:MongoDB Atlas 的实践与思考
【10月更文挑战第20天】本文探讨了MongoDB Atlas的核心特性、实践应用及对未来云原生数据库的思考。MongoDB Atlas作为云原生数据库服务,具备全球分布、完全托管、弹性伸缩和安全合规等优势,支持快速部署、数据全球化、自动化运维和灵活定价。文章还讨论了实施MongoDB Atlas的最佳实践和职业心得,展望了云原生数据库的发展趋势。