Superficial mongo db
Click here to load reader
-
Upload
dae-myung-kang -
Category
Technology
-
view
1.053 -
download
0
Transcript of Superficial mongo db
Superficial MongoDB
MongoDB NoSQL
Document
BSON
Document-Oriented Storage Full Index Support
Replication & High Availability
Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS
Document-Oriented Storage Full Index Support
Replication & High Availability
Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS
Document-Oriented > db.users.insert( { _id : "alex", name: { first:"Alex", last:"Benisson" }, karma : 1.0 } )
> db.posts.findOne() { _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", title : "No Free Lunch", text : "This is the text of the post. It could be very long.", tags : [ "business", "ramblings" ], votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), comment : "I agree." }, { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), comment : "You must be joking. etc etc ..." } ] }
Full-Index Support > db.things.ensureIndex({j:1});
> db.things.ensureIndex({"address.city": 1})
> db.things.ensureIndex({j:1, name:-1});
> db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } ); > db.factories.ensureIndex( { metro : 1 } ); // this query can use the above index: > > db.factories.find( { metro: { city: "New York", state: "NY" } } ); // this one too, as {city:"New York"} < {city:"New York",state:"NY"} > db.factories.find( { metro: { $gte : { city: "New York" } } } ); // this query does not match the document because the order of fields is significant > db.factories.find( { metro: { state: "NY" , city: "New York" } } );
Replication Asynchronous Replication
HA & FailOver Only Write to Primary Can read from Secondary
Op Ordinal: Increasing ordinal to represent each operation
Using Server ID + Op Ordinal
Picking Primary 1. Get Max LocalOpOrdinal from each Server 2. if a majority of servers are not up (from this server's POV), remain in Secondary mode and stop. 3. if the last op time seems very old, stop and await human intervention. 4. else, using a consensus protocol, pick the server with the highest maxLocalOpOrdinal as the Primary.
TIPs.
Use 64bit Machine MongoDB Use Memory-Mapped File
In 32bit. DB Size can’t over 2.5GB
MongoDB is needed Big Memory
Use Replica Set Use Replica Set and Journaling
Use Lastest Version 2.0.2 is better than 1.8.x
MongoDB has global Lock
1.8.x uses global Write Lock 2.0.x uses write with yield.
Not supports db or collection lock
Use Big Memory Disk Op is slower than Memory Op
Shard
Shard Architecture
Basic
Replication unit is chunk.
Chunk: 64mb or 100,000 objects
Chunk Count > 9
Data is split up into Chunks
Mongod
Replica Set(3 mongod)
Data Store
Mongos
StateLess
Routing to Shard
Proxy
Mongod configSvr
Can’t use Replica Set or M/A
1(test) or 3(real)
mongod
Mongod configSvr
Changes are made with 2PC
If any are down, meta data goes read only
System is online as long as 1/3 is up
Use Scale Up than Sharding
Difficult to find good Shard Key.
Not Support Data Center awareness Add memory and hdd, ssd
Object Id_
Object Id_
12 bytes
Replica Set
Operations
Default: Write/read operation goes to master
Can read from slaves.
Thank you!