superficial mongo db
TRANSCRIPT
![Page 2: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/2.jpg)
MongoDB NoSQL
Document
BSON
![Page 3: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/3.jpg)
Document-Oriented Storage Full Index Support
Replication & High Availability
Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS
![Page 4: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/4.jpg)
Document-Oriented Storage Full Index Support
Replication & High Availability
Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS
![Page 5: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/5.jpg)
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 ..." } ] }
![Page 6: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/6.jpg)
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" } } );
![Page 7: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/7.jpg)
Replication Asynchronous Replication
![Page 8: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/8.jpg)
HA & FailOver Only Write to Primary Can read from Secondary
Op Ordinal: Increasing ordinal to represent each operation
Using Server ID + Op Ordinal
![Page 9: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/9.jpg)
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.
![Page 10: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/10.jpg)
TIPs.
![Page 11: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/11.jpg)
Use 64bit Machine MongoDB Use Memory-Mapped File
In 32bit. DB Size can’t over 2.5GB
MongoDB is needed Big Memory
![Page 12: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/12.jpg)
Use Replica Set Use Replica Set and Journaling
![Page 13: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/13.jpg)
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
![Page 14: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/14.jpg)
Use Big Memory Disk Op is slower than Memory Op
![Page 15: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/15.jpg)
Shard
![Page 16: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/16.jpg)
Shard Architecture
![Page 17: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/17.jpg)
Basic
Replication unit is chunk.
Chunk: 64mb or 100,000 objects
Chunk Count > 9
Data is split up into Chunks
![Page 18: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/18.jpg)
Mongod
Replica Set(3 mongod)
Data Store
![Page 19: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/19.jpg)
Mongos
StateLess
Routing to Shard
Proxy
![Page 20: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/20.jpg)
Mongod configSvr
Can’t use Replica Set or M/A
1(test) or 3(real)
mongod
![Page 21: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/21.jpg)
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
![Page 22: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/22.jpg)
Use Scale Up than Sharding
Difficult to find good Shard Key.
Not Support Data Center awareness Add memory and hdd, ssd
![Page 23: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/23.jpg)
Object Id_
![Page 24: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/24.jpg)
Object Id_
12 bytes
![Page 25: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/25.jpg)
Replica Set
![Page 26: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/26.jpg)
Operations
Default: Write/read operation goes to master
Can read from slaves.
![Page 27: Superficial mongo db](https://reader037.vdocuments.us/reader037/viewer/2022100223/55568f8ad8b42a182f8b4e6a/html5/thumbnails/27.jpg)
Thank you!