• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
はじめてのMongoDB
 

はじめてのMongoDB

on

  • 19,318 views

 MongoDBの初心者向け資料です。SQLとの比較からMongoDBを理解する章を中心に展開していきます。また、Replication・Shardingに関しては別章で詳しく紹介し...

 MongoDBの初心者向け資料です。SQLとの比較からMongoDBを理解する章を中心に展開していきます。また、Replication・Shardingに関しては別章で詳しく紹介します。
 この資料をきっかけに多くの方がMongoDBを知り、触れるきっかけになればと思います。

Statistics

Views

Total Views
19,318
Views on SlideShare
13,821
Embed Views
5,497

Actions

Likes
45
Downloads
252
Comments
0

18 Embeds 5,497

http://blog.bot.vc 5276
http://paper.li 122
http://miff.blog.so-net.ne.jp 25
http://us-w1.rockmelt.com 19
http://a0.twimg.com 13
http://twitter.com 10
https://twitter.com 9
http://slide.yoshiday.net 7
http://webcache.googleusercontent.com 4
http://localhost 2
https://www.google.co.jp 2
http://tweetedtimes.com 2
https://www.google.co.kr 1
http://ytnobody.net 1
http://b.hatena.ne.jp 1
http://www.onlydoo.com 1
http://nuevospowerpoints.blogspot.com 1
http://www.google.co.jp 1
More...

Accessibility

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 はじめてのMongoDB Presentation Transcript

    • http://blog.nahurst.com/visual-guide-to-nosql-systems
    • { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "abc", "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3], "dbref" : [_id1, _id2, _id3]}
    • { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "abc", "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3], "dbref" : [_id1, _id2, _id3]}
    • { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "abc", "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3], padding}
    • { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "def", "number" : 4, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3, 4, 5, 6], "newkey" : "In-place"}
    • { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "abc", "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3],}
    • $ mongod --master --dbpath /data/masterdb/ --rest$ mongod --slave --source <masterhostname>[:<port>]--dbpath /data/slavedb/ --rest
    • $ mongod --replSet setname --rest> config = {_id: mySet, members: [ {_id: 0, host: host1:27017, priority: 1.0}, {_id: 1, host: host2:27018’, priority: 0.5}, {_id: 2, host: host3:27019, priority: 0.0} ] }> rs.initiate(config)> rs.status() //
    • Cluster Shard Servers (Data) config Servers (Shard Configration) shard1 shard2 shard3 [ a, f ) [ k, n) [ o, t ) Chunk [ f, k ) [ n, o ) [ t, } ) mongos Servers (Routers)
    • Shard 1 ( mongosprimary primary ) Shardcinfig Shard mongos
    • ~ mkdir -p shard/shard00~ mkdir -p shard/shard01~ mkdir -p shard/shard02~ mkdir -p shard/config~ mongod --shardsvr --port 27017 --dbpath shard/shard00~ mongod --shardsvr --port 27018 --dbpath shard/shard01~ mongod --shardsvr --port 27019 --dbpath shard/shard02~ mongod --configsvr --port 27020 --dbpath shard/config~ mongos --configdb localhost:27020 --port 27021
    • ➜ ~ mongo localhost:27021 // mongosMongoDB shell version: 1.8.0connecting to: localhost:27021/test> show dbsconfig 0.1875GB // sharding> db.adminCommand( { addshard: "localhost:27017", name: "shard00" } ){ "shardAdded" : "shard00", "ok" : 1 }> db.adminCommand( { addshard: "localhost:27018", name: "shard01" } ){ "shardAdded" : "shard01", "ok" : 1 }> db.adminCommand( { addshard: "localhost:27019", name: "shard02" } ){ "shardAdded" : "shard02", "ok" : 1 }
    • > db.adminCommand( { addshard: "set00/delta1:27017,delta2:27017", name:"shard00" } ){ "shardAdded" : "shard00", "ok" : 1 }> db.adminCommand( { addshard: "set01/delta3:27018,delta4:27018", name:"shard01" } ){ "shardAdded" : "shard01", "ok" : 1 }> db.adminCommand( { addshard: "set02/delta5:27019,delta6:27019", name:"shard02" } ){ "shardAdded" : "shard02", "ok" : 1 }
    • // mongos> db.adminCommand( { enablesharding : "test" } ){ "ok" : 1 }> db.adminCommand( { shardcollection : "test.myshard", key : { n : 1 } } ){ "collectionsharded" : "test.myshard", "ok" : 1 }
    • http://www.slideshare.net/doryokujin/mongo-sharding
    • http://www.mongodb.org/display/DOCSJP/Journaling
    • //> box = [[40.73083, -73.99756], [40.741404, -73.988135]]> db.places.find({"loc" : {"$within" : {"$box" : box}}})//> center = [50, 50]> radius = 10> db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}})// v1.9> polygonA = [ [ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ] ]> polygonB = { a : { x : 10, y : 20 }, b : { x : 15, y : 25 }, c : { x :20, y : 20 } }> db.places.find({ "loc" : { "$within" : { "$polygon" : polygonA } } })> db.places.find({ "loc" : { "$within" : { "$polygon" : polygonB } } })
    • ➜ ~ mongofiles listconnected to: 127.0.0.1➜ ~ mongofiles put music1.mp3connected to: 127.0.0.1added file: { _id: ObjectId(4df17f8d9d47ba5c0247e72e),filename: "music1.mp3", chunkSize: 262144, uploadDate: newDate(1307672462538), md5:"9ee9472200a2e18bf376ce622c3b0055", length: 11183104 }done!➜ ~ mongofiles list -v // -vFri Jun 10 11:21:05 creating new connection to:127.0.0.1Fri Jun 10 11:21:05 BackgroundJob starting:connected to: 127.0.0.1music.mp3 11183104
    • ➜ ~ mongofiles put music2.mp3connected to: 127.0.0.1added file: { _id: ObjectId(4df181fc5e354129e833193f),filename: "music2.mp3", chunkSize: 262144, uploadDate: newDate(1307673086293), md5:"9d4f424fa1843711e196e502d8a00183", length: 12225353 }done!➜ ~ mongofiles listconnected to: 127.0.0.1music1.mp3 11183104music2.mp3 12225353➜ ~ mongofiles search .mp3connected to: 127.0.0.1music1.mp3 11183104music2.mp3 12225353
    • Map-Reduce on Mongo