Prezi

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in the manual

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Why is my MongoDB slow?

No description
by Pradip Hudekar on 28 November 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Why is my MongoDB slow?

Why is my MongoDB slow?
I have heard of a cool DB!!
It is too fast..
It is a document store
It is just like RDBMS
I think collections are like tables
You can do joins too
It is very easy to scale with sharding
Wow, replica sets will make sure my data is always safe
It all seems to work fine...
God's gift to Mankind
It is time to go LIVE
DB is taking long time to respond
Why can't I see updated profile?
Looks like some of the data is lost
Something is Wrong
I think MongoDB SUCKS
It is all MongoDB's fault
what is MongoDB?
A BSON Document Database
{
"forename"
: "James",
"surname"
: "Bond",
"fictional"
: true,
"age"
: 35,
"interests"
: [ "girls", "guns" ],
"movies"
: [
{
"title"
: "SkyFall",
"releaseYear"
: 2012,
}
]
}
Simple to use
db.agents.find({
"surname"
: "Bond"})
Remember
MongoDB is not solution to all DB Problems
Easy installation and setup
Easy to work with
MongoDB is certainly best choice in some of the scenarios
How would I know If I can use it?
Does your data fits document model?
Do you need transactions?
Do you need real time aggregation for reporting?
Are your queries well defined?
Focus on Schema
MongoDB is not schema less, it has flexible schema
Think about denormalization
Keep in mind the document size limit (16 MB)
Support for maximum 100 Nested Documents
References can be used as exceptions
Example of an ideal Schema
{
"title"
: "Lagaan",
"director"
: "Ashutosh Gowarikar",
"releaseYear"
: 2001,
"averageRating"
: 8.1,
"favourite"
: true,
"cast"
: [
"Aamir Khan",
"Gracy Singh" ,
"Rachel Shelley"],
"reviews"
: [
{
"title"
: "A must see for all Indian cricket fans!",
"date"
: ISODate("10-08-2002"),
"summary"
: "Very good movie.."
"rating"
: 9.0
}
]
}
Indexes
Why do I need them?
Faster Reads
Faster Updates
Faster Deletes
Maintaining Unique Keys
Improving Sharding
Various Indexes in MongoDB
Creating index
db.movies.ensureIndex({
"title"
: 1});
db.movies.getIndexes();
Default Index
{
"v"
: 1,
"key"
: {
"_id"
: 1
},

"ns"
: "<db>.<collection>",

"name"
: "_id_"
}
Single Field Index
db.movies.ensureIndex({
"releaseYear"
: 1})
Compound Index
db.movies.ensureIndex(
{
"releaseYear"
: 1,
"averageRating"
: -1
});
Multikey Index
db.movies.ensureIndex({
"cast"
: 1 })
Other Indexes
Geo spatial Indexes
Text Index
Hashed Index
db.people.ensureIndex({
"email"
: 1}, {
"unique"
: true})
Getting indexes
Deleting indexes
db.movies.dropIndex({
"title"
: 1})
Index Creation Options
db.movies.ensureIndex({
"averageRating"
: -1})
Remove Duplicates
db.people.ensureIndex({
"email"
: 1},
{
"unique"
: true,
"dropDups"
: true
})
Sparse Index
db.movies.ensureIndex({
"awards"
: 1}, {
"sparse"
: true})
Named Index
db.people.ensureIndex({
"country"
: 1 ,
"city"
: 1 },
{
"name"
: "locality"})
Unique Index
Improving Sorting
Providing a Hint
Index Selectivity
Profiling
Suggesting an index to use
$natural
Sparse indexes in hint can give wrong results
Sparse Ahead
Makes more sense in Compound Index
Filter most of the data using Index
How to detect slow queries
Default logging
Profiling levels
0 - No Profiling
1 - Only slow operations
2 - All operations
db.getProfilingStatus()
db.setProfilingLevel(1,200)
How to be sure?
db.movies.find({
"title"
:/^A/}).explain()
ExperTalks - November 2013
See the full transcript