Más contenido relacionado
La actualidad más candente (20)
Similar a はじめてのMongoDB (20)
Más de Takahiro Inoue (20)
はじめてのMongoDB
- 16. {
"_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]
}
- 17. {
"_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]
}
- 20. {
"_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
}
- 21. {
"_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"
}
- 25. {
"_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],
}
- 36. $ mongod --master --dbpath /data/masterdb/ --rest
$ mongod --slave --source <masterhostname>[:<port>]
--dbpath /data/slavedb/ --rest
- 38. $ 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() //
- 47. 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)
- 48. Shard
1
( mongos
primary primary
)
Shard
cinfig Shard
mongos
- 53. ~ 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
- 54. ➜ ~ mongo localhost:27021 // mongos
MongoDB shell version: 1.8.0
connecting to: localhost:27021/test
> show dbs
config 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 }
- 55. > 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 }
- 56. // mongos
> db.adminCommand( { enablesharding : "test" } )
{ "ok" : 1 }
> db.adminCommand( { shardcollection : "test.myshard", key : { n : 1 } } )
{ "collectionsharded" : "test.myshard", "ok" : 1 }
- 63. //
> 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 } } })
- 65. ➜ ~ mongofiles list
connected to: 127.0.0.1
➜ ~ mongofiles put music1.mp3
connected to: 127.0.0.1
added file: { _id: ObjectId('4df17f8d9d47ba5c0247e72e'),
filename: "music1.mp3", chunkSize: 262144, uploadDate: new
Date(1307672462538), md5:
"9ee9472200a2e18bf376ce622c3b0055", length: 11183104 }
done!
➜ ~ mongofiles list -v // -v
Fri Jun 10 11:21:05 creating new connection to:127.0.0.1
Fri Jun 10 11:21:05 BackgroundJob starting:
connected to: 127.0.0.1
music.mp3 11183104
- 66. ➜ ~ mongofiles put music2.mp3
connected to: 127.0.0.1
added file: { _id: ObjectId('4df181fc5e354129e833193f'),
filename: "music2.mp3", chunkSize: 262144, uploadDate: new
Date(1307673086293), md5:
"9d4f424fa1843711e196e502d8a00183", length: 12225353 }
done!
➜ ~ mongofiles list
connected to: 127.0.0.1
music1.mp3 11183104
music2.mp3 12225353
➜ ~ mongofiles search .mp3
connected to: 127.0.0.1
music1.mp3 11183104
music2.mp3 12225353