Getting Start on Mongodb
题记:最近老和同学聊到non-relational-db的领域,今天恰巧看到robbin大哥对这个领域的见解,让我心情澎拜。
WEB2.0的兴起暴露了关系型数据库的弊端,推动了非关系型数据库的发展。
对于WEB应用,强调了高读写操作,海量数据存储,横向扩展,正如robbin大哥说的,关系型数据库的优点在WEB应用面前变得无用武之地:事务一致性、多表查询。
解决高读写操作则牺牲一致性,内存操作,并异步flush到文件系统;
解决海量数据则写自己的文件系统;
解决横向扩展需要解决集群的可拔插。
各类non-relational数据库都有各自的特点,MongoDB能支撑海量数据,TC/TT提供很好的高并发读写性能,Cassandra适合集群(它更像一组网络服务尔非数据库)。
个人觉得海量数据和对用户提供的高并发必然集群,所以即便MongoDB很好支持了海量存储,但不知集群方面做的怎样,所以Cassandra是值得学习的。
关于NOSQL的产品之一——MongoDB
MongoDB—Kyle Banker—10gen
MongoDB is JSON document oriented database. These documents are stored in the database as BSON (binary JSON). BSON is efficient, fast, and is richer in type than JSON (i.e. regex support). Documents are grouped in collections which are analogous to relational tables, but are schema free.
GridFS is a specication for storing large binary files like images and videos in MongoDB. Every document has a 4MB limit. GridFS chuncs the large files into such 4MB parts inside a collection, with a saperate metadata collection. MusicNation.com stores all music and video alongside the application data in MongoDB (about 1TB).
MongoDB has its own wire protocol with socket drivers for several languages. The drivers serializes the data to BSON before transfer.
Replication is used for failover and redundancy. Most commonly a master-slave setup is used. It’s also possible to setup a replica pair architecture.
MongoDB provides a custom query language which should be as powerful as SQL. MongoDB understands the internal structures of its documents which enables dynamic queries. Map/reduce functions are also supported in the query language.
BusinessInsider.com has been using MongoDB for two years with 12M page views/month. They like the simplification of the data model. Posts for instance have embedded comments. They also store real-time analytics in MongoDB which enables fast inserts and eased data analysis with dymanic queries. Uses a single MongoDB database server, 3 Apache web servers, and Memcached caching only on the front page.
TweetCongress.org are users of MongoDB and likes that code defines the schema, and one can therefore version control the schema. They use a single master with snapshots on a 64-bit EC2 instance.
SourceForge.net had a large redesign this summer where they moved to MongoDB. Their goal was to store the front pages, project pages, and download pages in a single document. It’s deployed with one master and 5-6 read-only slaves (obviously scaled for reads and reliability).
Download
The easiest (and recommended) way to install MongoDB is to use the pre-built binaries.
32-bit binaries
Download and extract the 32-bit .zip. The "Production" build is recommended.
64-bit binaries
Download and extract the 64-bit .zip.
Note: 64-bit is recommended, although you must have a 64-bit version of Windows to run that version.
Unzip
Unzip the downloaded binary package to the location of your choice. You may want to rename mongo-xxxxxxx to just "mongo" for convenience.
Create a data directory
By default MongoDB will store data in C:\data\db, but it won't automatically create that folder, so we do so here:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">C:\> mkdir \dataC:\> mkdir \data\db
页:
[1]