Top Banner
MongoDB
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to MongoDB

MongoDB

Page 2: Introduction to MongoDB

What is a document?

• MS Word file stored in Sharepoint

• JSON or XML

Page 3: Introduction to MongoDB

What is a document?

{“campaign_id”: 12,“created_on”: ISODate("2013-04-08T18:10:48Z")“name”: “Trade LG”,“published”: true,“status_id”: 2

}

Page 4: Introduction to MongoDB

What is a document?

{“campaign_id”: 12,“created_on”: ISODate("2013-04-08T18:10:48Z")“name”: “Trade LG”,“published”: true,“status_id”: 2,“keywords”: [ “trade lg”, “yahoo”, “test” ]

}

Page 5: Introduction to MongoDB

What is a document?{

“campaign_id”: 12,“created_on”: ISODate("2013-04-08T18:10:48Z")“name”: “Trade LG [01JUL2013] [1308]”,“published”: true,“status_id”: 2,“keywords”: [ “trade lg”, “yahoo”, “test” ],“placements”: [

{ “placement_id”: 14,“name”: “[3495] [01JUL2013] ROS 20minutes 300X250”

}]

}

Page 6: Introduction to MongoDB

What is a document?{

“campaign_id”: 12,“created_on”: ISODate("2013-04-08T18:10:48Z")“name”: “Trade LG [01JUL2013] [1308]”,“published”: true,“status_id”: 2,“keywords”: [ “trade lg”, “yahoo”, “test” ],“placements”: [

{ “placement_id”: 14,“name”: “[3495] [01JUL2013] ROS 20minutes 300X250”,“funnels”: [

{ “funnel_id”: 15, “name”: “funnel_1”, “published”: true },{ “funnel_id”: 16 “name”: “funnel_2”, “published”: false },{ “funnel_id”: 17, “name”: “funnel_3”, “published”: true }

]}

]}

Page 7: Introduction to MongoDB

Indexes

• ensureIndex( { “created_on”:1 } )

• ensureIndex( { “published”: 1, “status_id”: 1} )

• ensureIndex( { “keywords”: 1} )

• ensureIndex( { “placements.funnels.published”: 1 } )

Page 8: Introduction to MongoDB

Querying

• Query by example

• find({“campaign_id”: 12})

• find({ “published”: true, “created_on”: { $gt: ISODate("2013-04-01") }});

Page 9: Introduction to MongoDB

Scalability

• Horizontal

• Master/Slave replication

• Sharding

Page 10: Introduction to MongoDB

Read Optimization

Page 11: Introduction to MongoDB

Write Optimization

Page 12: Introduction to MongoDB

Backup Strategies

• Replication

• Files backup

• mongodump + mongorestore

• Journal backup

Page 13: Introduction to MongoDB

Deployment Options

• Hosted solutions

• Single node

• Replica set

• Replication across data centers

Page 14: Introduction to MongoDB

Who uses MongoDB?

Page 15: Introduction to MongoDB

Internal POC• 24,000,000+ activities

• 11GB

• 14,500 inserts per second

• Fetch activities by user id:44,438 results, ~60ms

• Fetch activities by type name:3,585,101 results, ~6942ms

• Single server: M1-Large(300$)

Page 16: Introduction to MongoDB