mongodb-introduction

  • 2,624 views
Uploaded on

NoSQL Taiwan #1 Talk

NoSQL Taiwan #1 Talk

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,624
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
68
Comments
0
Likes
6

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. MongoDBIntroduction 2012/02/16 Tse-Ching Ho 何澤清
  • 2. About meRuby Developer Twitter: tsechingho2011: 開始使用 NoSQL Skype: tsechingho1978工作。 GitHub: https://2011.9-present: github.com/tsechingho陽明大學生物資訊所資深工程師
  • 3. 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
  • 4. What & Why
  • 5. Size matters
  • 6. Type matters
  • 7. Place matters
  • 8. Time matters
  • 9. Money matters
  • 10. Person mattersEasy learn, Easy use, Easy designQuick, AgileFlexibilityNice APIs are best &iends
  • 11. Specification
  • 12. MongoDB vs RDBMS
  • 13. 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
  • 14. Key PointsDocument based, Eventual consistencyCo#ection driven ReplicationEmbeded, Referenced ShardingSchema &ee pros: easy additionDistributed cons: fault tolerance,Durability migration tolerance
  • 15. Install
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. Configurationvim $(brew --prefix mongodb)/mongod.confvim /etc/mongodb.confdbpath = /usr/local/var/mongodblogpath = /usr/local/var/log/mongodbbind_ip = 127.0.0.1
  • 20. Syntax
  • 21. BSON{ "_id" : ObjectId("4d3ed089#60ab534684b7e9"), "title" : "Sir", "name" : { "_id" : ObjectId("4d3ed089#60ab534684b7ff "), "first_name" : "Durran" }, "addresses" : [ { "_id" : ObjectId("4d3ed089#60ab534684b7e0"), "city" : "Berlin", "country" : "Deutschland" } ]}
  • 22. 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})
  • 23. 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})
  • 24. 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
  • 25. ELSEIndexMap / ReduceTransaction / ACID
  • 26. Application
  • 27. Replica Setsasynchronous replicationdistributing read loadautomatic recoveryautomatic failoverauto election of primaryprimary for writes replacement of master-slave
  • 28. Demo Codehttps://github.com/tsechingho/mongodb-tutorial
  • 29. ShardingBalancing Shards (Replica Sets)Failover Config ServerScaling model Mongos (Router, Routing Processes)
  • 30. Sharding Components
  • 31. Servers layout
  • 32. Sharding Architecture
  • 33. Usage CasesSma# nested data set Reproducible data set Comments, Tweets, API fetched data SMS Analysis data Manipulation logTime careless CMS
  • 34. Tools
  • 35. MongoHubManagementhttp://mongohub.todayclose.com/
  • 36. Mongo 3Data manipulationhttps://github.com/derailed/mongo3
  • 37. Thought
  • 38. References
  • 39. http://nosql-database.orghttp://blog.nosqlfan.comhttp://www.mongodb.orghttp://mongoid.org/