mongodb-introduction
Upcoming SlideShare
Loading in...5
×
 

mongodb-introduction

on

  • 2,928 views

NoSQL Taiwan #1 Talk

NoSQL Taiwan #1 Talk

Statistics

Views

Total Views
2,928
Views on SlideShare
2,925
Embed Views
3

Actions

Likes
6
Downloads
66
Comments
0

3 Embeds 3

http://static.ak.facebook.com 1
http://www.hanrss.com 1
https://si0.twimg.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

mongodb-introduction mongodb-introduction Presentation Transcript

  • MongoDBIntroduction 2012/02/16 Tse-Ching Ho 何澤清
  • About meRuby Developer Twitter: tsechingho2011: 開始使用 NoSQL Skype: tsechingho1978工作。 GitHub: https://2011.9-present: github.com/tsechingho陽明大學生物資訊所資深工程師
  • Not Only SQLKey V alue Store: Column Store:Memcached, Redis, Cassandra, Hadoop/Couchbase Server, HBase, Hypertable,BerkeleyDB, Riak, Amazon SimpleDBDynamoDB Graphic Database:Document Store: Neo4j, InfiniteGraph,MongoDB, CouchDB, InfoGrid, A#egroGraph,OrientDB, RavenDB HyperGraphDB
  • What & Why
  • Size matters
  • Type matters
  • Place matters
  • Time matters
  • Money matters
  • Person mattersEasy learn, Easy use, Easy designQuick, AgileFlexibilityNice APIs are best &iends
  • Specification
  • MongoDB vs RDBMS
  • FeaturesWritten in: C++ Better update-in-place than CouchDBMain point: Retains some &iendly Uses memory mapped files for dataproperties of SQL. (Query, index) storageLicense: AGPL (Drivers: Apache) Performance over featuresProtocol: Custom, binary (BSON) Journaling (with --journal) is best turnedMaster/slave replication (auto failover onwith replica sets) On 32bit systems, limited to ~2.5GbSharding built-in An empty database takes up 192MbQueries are javascript expressions GridFS to store big data + metadata (notRun arbitrary javascript functions actua#y an FS)server-side Has geospatial indexing
  • Key PointsDocument based, Eventual consistencyCo#ection driven ReplicationEmbeded, Referenced ShardingSchema &ee pros: easy additionDistributed cons: fault tolerance,Durability migration tolerance
  • Install
  • Mac/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"brew insta# mongodbcp /usr/local/Ce#ar/mongodb/2.0.2-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
  • Debianecho "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen" > /etc/apt/sources.list.d/10gen.listapt-key adv --keyserver keyserver.ubuntu.com --recv7F0CEB10aptitude updateaptitude insta# mongodb-10gen
  • Ruby & Mongoidbash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-insta#er )rvm insta# ruby-1.9.3gem insta# mongoid
  • Configurationvim $(brew --prefix mongodb)/mongod.confvim /etc/mongodb.confdbpath = /usr/local/var/mongodblogpath = /usr/local/var/log/mongodbbind_ip = 127.0.0.1
  • Syntax
  • BSON{ "_id" : ObjectId("4d3ed089#60ab534684b7e9"), "title" : "Sir", "name" : { "_id" : ObjectId("4d3ed089#60ab534684b7ff "), "first_name" : "Durran" }, "addresses" : [ { "_id" : ObjectId("4d3ed089#60ab534684b7e0"), "city" : "Berlin", "country" : "Deutschland" } ]}
  • Database Manipulationmongo > db.things.count()> help > db.things.dataSize()> show dbs > db.things.find()> use demo > db.things.remove()> db.things > db.dropDatabase()> db.things.help()> db.things.save({name:NoSQL Taiwan})
  • CRUDCreate Co#ection Update Co#ection> db.things.insert({db: > db.things.update({db:mongodb, type:native}) mongodb}, {db: redis}) > db.things.update({db:Retrieve Co#ection redis}, {$set: {type: copy}})> db.things.find({db:mongodb}) Delete Co#ection> db.things.find({db: > db.things.remove({db:mongodb}, {type: false}) redis})
  • QueryGeneral find Conditional Operators <, <=, >, >= db.things.find( { x : 3, y : "foo" } ); $a# db.things.find({j: {$ne: 3}, k: {$gt: $exists 10} }); $modRegular Expressions $ne db.customers.find( { name : $in { $regex : acme.*corp, $options: $nin i } } ); $nor $or $and $size $type
  • ELSEIndexMap / ReduceTransaction / ACID
  • Application
  • Replica Setsasynchronous replicationdistributing read loadautomatic recoveryautomatic failoverauto election of primaryprimary for writes replacement of master-slave
  • Demo Codehttps://github.com/tsechingho/mongodb-tutorial
  • ShardingBalancing Shards (Replica Sets)Failover Config ServerScaling model Mongos (Router, Routing Processes)
  • Sharding Components
  • Servers layout
  • Sharding Architecture
  • Usage CasesSma# nested data set Reproducible data set Comments, Tweets, API fetched data SMS Analysis data Manipulation logTime careless CMS
  • Tools
  • MongoHubManagementhttp://mongohub.todayclose.com/
  • Mongo 3Data manipulationhttps://github.com/derailed/mongo3
  • Thought
  • References
  • http://nosql-database.orghttp://blog.nosqlfan.comhttp://www.mongodb.orghttp://mongoid.org/