MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB

MongoDB
MongoDBMarketing Ninja at MongoDB
Chris Harris
Tips and Tricks++ for Querying MongoDB
Chris Harris
Lead Technical Expert for Queries and Indexing
Introductions
Diego
Introductions
I identified slow queries.
What index do I make?
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Equality Sort Range "Rule"
E – S - R
The ordering of index keys in a
compound index is critically
important. E-S-R provides
guidance that is useful in most
cases:
• Equality first
• Sort next
• Range last
E – S - R
The ordering of index keys in a
compound index is critically
important. E-S-R provides
guidance that is useful in most
cases:
• Equality first
• Sort next
• Range last
What is the difference between
Equality and Range?
Definitions
Equality Fields
An exact match on a single
value. For example:
• {x:123}
• {x:{$eq:123}}
• {x:"123"}
• {"x.y":123}
Definitions
Equality Fields
An exact match on a single
value. For example:
• {x:123}
• {x:{$eq:123}}
• {x:"123"}
• {"x.y":123}
Sort
The (entire) requested sort.
.sort({x:1, y:-1})
Definitions
Equality Fields
An exact match on a single
value. For example:
• {x:123}
• {x:{$eq:123}}
• {x:"123"}
• {"x.y":123}
Sort
The (entire) requested sort.
.sort({x:1, y:-1})
Range Predicates
Any predicates that are not
exact matches. Some
operators include:
• {x:{$gt:0}}
• {x:{$lte:1000}}
Equality
Equality keys are placed first in any order
If present in the query shape, equality fields should always form the
prefix for the index.
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
Equality
Equality keys are placed first in any order
If present in the query shape, equality fields should always form the
prefix for the index.
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
Equality
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{gamertag: "Ace", score: 100}
{gamertag: "Ace", score: 99,999}
{gamertag: "Bob", score: 15,000}
{gamertag: "Bob", score: 50,000}
Equality
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {}
{}{}
100 15,000 50,000 99,999
Ace Bob Bob Ace
{gamertag: "Ace", score: 100}
{gamertag: "Ace", score: 99,999}
{gamertag: "Bob", score: 15,000}
{gamertag: "Bob", score: 50,000}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100 15,000 50,000 99,999
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
Ace Bob Bob Ace
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
100 99,999 15,000 50,000
{} {} {} {}
Equality
100
Ace Bob
99,999 15,000 50,000
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100
Ace Bob
99,999 15,000 50,000
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality
100
Ace Bob
99,999 15,000 50,000
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
{} {} {} {}
Equality before Range
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
R
E R
E
Sort
Sort fields are placed next
Placing sort predicates after sequential equality keys allow for the
index to:
• Provide a non-blocking sort.
• Minimize the amount of scanning required.
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
{}
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
100
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
100 15,000 50,000 99,999
Ace Bob Bob Ace
{} {}{} {}
Sort
Ace Bob Bob Ace
100 99,999 15,000 50,000
{} {} {} {}
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
Sort
100
Ace Bob
{}
99,999 15,000 50,000
{} {}
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
{}
Sort
100
Ace Bob
{}
99,999 15,000 50,000
{} {}
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
{}
Sort
100
Ace Bob
{}
99,999 15,000 50,000
{} {}
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
{}
Sort
100
Ace Bob
{}
99,999 15,000 50,000
{} {}
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
{}
Sort after Equality
db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
S
E S
E
Range
Range fields are usually last
Generally range predicates should be placed last.
This allows them to still participate in filtering the data, but does not
force a blocking sort.
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
Range after Equality
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
R
E R
E
Range
db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
Should range come after sort
too?
R
E R
E
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Should range come after sort
too?
R
E R
E
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
100 15,000 50,000 99,999
Ace Bob Cali Ace
{} {}{} {}
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
100 15,000 50,000 99,999
Ace Bob Cali Ace
{} {}{} {}{1}{3}{2}
{1}{3}{2}
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
{1}{3}{2}
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Blocking SortBlocking Sort
BS
{1}{3}{2}
Range
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
BS
Range
100 15,000 50,000 99,999
Ace Bob Cali Ace
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
Ace Bob Cali Ace
100 15,000 50,00099,999
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range
100 15,000 50,00099,999
Ace Bob Cali
{1} {3}{2}{}
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
Range after Sort
db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
BS
R S
R
S
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Predicate Type Check
What are the types of the following operators?
Predicate Type Check - Inequality
Inequality operators, such as the
following, are E, S, or R?
§ $ne:123
§ $nin:[1,2]
Range!
Predicate Type Check - Inequality
Inequality operators, such as the
following, are E, S, or R?
§ $ne:123
§ $nin:[1,2]
Range!
How do you know?
Predicate Type Check - Inequality
Inequality operators, such as the
following, are E, S, or R?
§ $ne:123
§ $nin:[1,2]
Range!
"indexBounds" : {
"x" : [
"[MinKey, 123.0)",
"(123.0, MaxKey]"
]
}
Predicate Type Check - Inequality
Range!
"indexBounds" : {
"x" : [
"[MinKey, 123.0)",
"(123.0, MaxKey]"
]
}
50 123 999
Predicate Type Check - Inequality
Range!
"indexBounds" : {
"x" : [
"[MinKey, 123.0)",
"(123.0, MaxKey]"
]
}
50 123 999
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
planecar racecar
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
planecar racecar
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
planecar racecar
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
raincarry Carpool
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
raincarry Carpool
Predicate Type Check - Regex
Regex operators, such as the
following, are E, S, or R?
§ {str:/car/}
§ {str:/^car/i}
Range!
raincarry Carpool
Predicate Type Check - $in
$in filters, as demonstrated below,
are E, S, or R?
§ {field:{$in:[1,3]}}
… it depends! Can be Equality or
Range in terms of the key ordering
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
BS
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]",
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
Predicate Type Check - $in
{field:{$in:[1,3]}}
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
{} {} {} {} {} {}
Predicate Type Check - $in
1 2 3
C G B F A D
1 2 3
C G B F A D
{} {} {} {} {} {} {} {} {} {} {} {}
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
"indexBounds" : {
"field" : [
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
Predicate Type Check - $in
{field:{$in:[1,3]}}
"indexBounds" : {
"field" : [
"[1.0, 1.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
"indexBounds" : {
"field" : [
"[3.0, 3.0]"
],
"sortField" : [
"[MinKey, MaxKey]"
]
}
1 2 3
C G B F A D
1 2 3
C G B F A D
Sort Merge
{} {} {} {} {} {} {} {} {} {} {} {}
Predicate Type Check - $in
BS
Depends on the length of the $in list
S M
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Sequential Equality Keys
Does it matter if there is missing predicate in the equality key list?
For example, given:
§ Query: {gamertag:"Ace", game: "Halo"}
§ Index: {gamertag:1, date:1, game:1}
Is that index as efficient as the following one?
{gamertag:1, game:1, date:1}
Sequential Equality Keys
Answer: It depends! … but probably not
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario Halo
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
Halo
Sequential Equality Keys
Ace
Mario Halo
2016 2017
Mario
2018 2019
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"date" : [
"[MinKey, MaxKey]"
],
"game" : [
"["Halo", "Halo"]"
]
}
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"game" : [
"["Halo", "Halo"]"
]
}
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"game" : [
"["Halo", "Halo"]"
]
}
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"game" : [
"["Halo", "Halo"]"
]
}
"indexBounds" : {
"gamertag" : [
"["Ace", "Ace"]"
],
"game" : [
"["Halo", "Halo"]"
],
"date" : [
"[MinKey, MaxKey]"
]
}
Sequential Equality Keys
Ace
2016 2017Mario2018 2019Halo
Sequential Equality Keys
R
E
E E
E
E
E
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Exceptions
Is this "rule" always optimal?
Not always.
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
"executionStats" : {
"nReturned" : 2,
"executionTimeMillis" : 23,
"totalKeysExamined" : 9001,
"totalDocsExamined" : 2,
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
1 5,000 9,0012 9,000
… …
2001 2000 2015 2019 2019
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
2001 2000 2015 2019 2019
{score:2} {score:1} {score:5000} {score:9001} {score:9000}
… …
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
… …
2000 2001 2015 2019 2019
{score:2} {score:1} {score:5000} {score:9001} {score:9000}
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
… …
2000 2001 2015 2019 2019
{score:2} {score:1} {score:5000} {score:9001} {score:9000}
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
… …
2000 2001 2015 2019 2019
{score:2} {score:1} {score:5000} {score:9001} {score:9000}
BS
"executionStats" : {
"nReturned" : 2,
"executionTimeMillis" : 0,
"totalKeysExamined" : 2,
"totalDocsExamined" : 2,
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
Ace
… …
2000 2001 2015 2019 2019
{score:2} {score:1} {score:5000}
"executionStats" : {
"nReturned" : 2,
"executionTimeMillis" : 0,
"totalKeysExamined" : 2,
"totalDocsExamined" : 2,
"executionStages" : {
"stage" : "SORT",
"memUsage" : 154,
"memLimit" : 33554432,
{score:9001}{score:9000}
BS
Exceptions
db.games
.find({gamertag:"Ace", date:{$gte:2019}})
.sort({score:1})
……… …
BS
S
R
E
R
E
E-S-R Guidance
A good starting place applicable to most use cases
Place keys in the following order:
• Equality first
• Sort next
• Range last
Remember that equality is an exact match of a single value
E-S-R Guidance
A good starting place applicable to most use cases
Place keys in the following order:
• Equality first
• Sort next
• Range last
Remember that equality is an exact match of a single value
I see isMultiKey:true in
the explain output. What
does that mean?
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Multikey
Index
A special type of index which
supports efficient querying for
array fields
Index Nomenclature
Single Field Index
The index entries reference
a single field in the
document
Can be Multikey
Compound Index
The index entries reference
more than one field in the
document
Can be Multikey
Multikey Index
There is separate entry in
the index for every array in
the document
Single Field Index
Ace Doyen
{ gamertag: "Ace",
games:["Mario", "Halo"] }
{ gamertag: "Doyen",
games:["Fortnite", "GTA", "Minecraft"] }{} {}
Single Field Index - Multikey
{} {}
MarioHaloGTAFortnite
Minecraft
DoyenAce
Compound Index - Multikey
{} {}
MarioHaloGTAFortnite
Minecraft
Compound Index - Multikey
HaloMinecraftGTAFortnite
Mario
AceDoyen
{}{}
We tried to use arrays but get
incorrect results and queries are
slow. What gives?
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
db.matches.find({ "players.name": "Ace",
"players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
db.matches.find({ "players.name": "Ace",
"players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
db.matches.find({ "players.name": "Ace",
"players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
{ _id: 3, players: [ { name: "Doyen", rank : 1 },
{ name: "Cali", rank : 2 } ] }
"You can specify the query such that either a single array element meets these conditions or
any combination of array elements meets the conditions."
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics - $elemMatch
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
Semantics - $elemMatch
{ _id: 1, players: [ { name: "Doyen", rank : 1 },
{ name: "Ace", rank : 2 } ] }
{ _id: 2, players: [ { name: "Ace", rank : 1 },
{ name: "Doyen", rank : 2 } ] }
db.matches.find({ "players.name": "Ace", "players.rank": 1 })
db.matches.find({ "players":
{ $elemMatch: { name: "Ace", "rank": 1} }
})
Semantics - $elemMatch
Use $elemMatch to query multiple fields of a single array element
Not necessary when querying on a single predicate
Semantics - $elemMatch
Use $elemMatch to query multiple fields of a single array element
Not necessary when querying on a single predicate
Okay, that change got us
correct results. But what
about the performance?
Roadmap
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
db.matches.find({
players:"Ace",
date:{
$gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28")
}
})
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
db.matches.find({
players:"Ace",
date:{
$gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28")
}
})
.explain()
…
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"(true, new Date(1551312000000)]"
]
}
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
db.matches.find({
players:"Ace",
date:{
$gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28")
}
})
.explain()
…
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"(true, new Date(1551312000000)]"
]
}
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
db.matches.find({
players:"Ace",
date:{
$gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28")
}
})
.explain()
…
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"(true, new Date(1551312000000)]"
]
}
Multikey Path Tracking
{
"_id" : 1,
"game" : "Halo",
"players" : [
"Ace",
"Doyen",
"Cali",
"Bob"
],
"date" : ISODate("2019-02-15T00:00:00Z")
}
db.matches.find({
players:"Ace",
date:{
$gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28")
}
})
.explain()
…
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"(true, new Date(1551312000000)]"
]
}
Multikey Path Tracking
Before MongoDB 3.4:
§ Database only contained coarse isMultiKey flag for index
§ Did not know which field was the array
§ Conservative behavior to ensure correct results
Multikey Path Tracking
Before MongoDB 3.4:
"stage" : "IXSCAN",
"indexName" : "players_1_date_1",
"isMultiKey" : true,
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"(true, new Date(1551312000000)]"
]
}
3.4+:
...
"multiKeyPaths" : {
"players" : [ "players" ],
"date" : [ ]
},
"indexBounds" : {
"players" : [
"["Ace", "Ace"]"
],
"date" : [
"[new Date(1548979200000),
new Date(1551312000000)]"
]
}
Multikey Path Tracking
Take advantage of the improvement
§ Index needs to be rebuilt when running 3.4 binaries
§ Just running on 3.4 is not sufficient
§ Look for multiKeyPaths field in explain output
§ v:2 index would be a deterministic check
§ Multikey index cannot cover queries on the array field
Multikey Path Tracking
Take advantage of the improvement
§ Index needs to be rebuilt when running 3.4 binaries
§ Just running on 3.4 is not sufficient
§ Look for multiKeyPaths field in explain output
§ v:2 index would be a deterministic check
§ Multikey index cannot cover queries on the array field
Wow! Everything is running at
Web Scale now!
Summary
§ E-S-R
§ Overview
§ Predicate Type Check
§ Sequential Prefix
§ Exceptions?
§ Multikey Index
§ Definition
§ Semantics
§ Performance
Q&A about Q&I
Additional Resources
Key Ordering Resources
Blog Post
My colleague Jesse wrote an article
which explores the performance
characteristics of different
arrangements.
MongoDB University
My colleague Kirby covers many
indexing topics in greater detail,
including key ordering, in M201:
MongoDB Performance.
Please provide Session Feedback
1. Go to slido.com
2. Enter event code #MDBW19
3. Click on Room Name and Provide Session
Feedback
Feedback poll will remain open for 10 minutes after the talk
ends
Questions?
Meet me now in the Leaf Lounge on the second floor of the
Partner Pavilion
YOU ARE IN MURRAY HILL
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
1 of 192

Recommended

MongoDB World 2019: The Sights (and Smells) of a Bad Query by
MongoDB World 2019: The Sights (and Smells) of a Bad QueryMongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad QueryMongoDB
3.9K views43 slides
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing by
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB
8.3K views211 slides
Indexing and Performance Tuning by
Indexing and Performance TuningIndexing and Performance Tuning
Indexing and Performance TuningMongoDB
3.1K views81 slides
Fast querying indexing for performance (4) by
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
21.7K views59 slides
Introduction to Mongodb execution plan and optimizer by
Introduction to Mongodb execution plan and optimizerIntroduction to Mongodb execution plan and optimizer
Introduction to Mongodb execution plan and optimizerMydbops
978 views28 slides
Indexing by
IndexingIndexing
IndexingMike Dirolf
6.2K views27 slides

More Related Content

What's hot

MongodB Internals by
MongodB InternalsMongodB Internals
MongodB InternalsNorberto Leite
10.3K views52 slides
Mongodb Aggregation Pipeline by
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipelinezahid-mian
14.5K views23 slides
Reading the .explain() Output by
Reading the .explain() OutputReading the .explain() Output
Reading the .explain() OutputMongoDB
1.1K views138 slides
Inside MongoDB: the Internals of an Open-Source Database by
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
52.5K views25 slides
MongoDB Fundamentals by
MongoDB FundamentalsMongoDB Fundamentals
MongoDB FundamentalsMongoDB
1.8K views46 slides
Understanding and tuning WiredTiger, the new high performance database engine... by
Understanding and tuning WiredTiger, the new high performance database engine...Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...Ontico
7K views31 slides

What's hot(20)

Mongodb Aggregation Pipeline by zahid-mian
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipeline
zahid-mian14.5K views
Reading the .explain() Output by MongoDB
Reading the .explain() OutputReading the .explain() Output
Reading the .explain() Output
MongoDB1.1K views
Inside MongoDB: the Internals of an Open-Source Database by Mike Dirolf
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
Mike Dirolf52.5K views
MongoDB Fundamentals by MongoDB
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
MongoDB1.8K views
Understanding and tuning WiredTiger, the new high performance database engine... by Ontico
Understanding and tuning WiredTiger, the new high performance database engine...Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...
Ontico7K views
Indexing and Query Optimization by MongoDB
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
MongoDB4.8K views
Sizing MongoDB Clusters by MongoDB
Sizing MongoDB Clusters Sizing MongoDB Clusters
Sizing MongoDB Clusters
MongoDB31.5K views
MongoDB Aggregation by Amit Ghosh
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
Amit Ghosh234 views
Mongo DB 성능최적화 전략 by Jin wook
Mongo DB 성능최적화 전략Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략
Jin wook17.6K views
The Basics of MongoDB by valuebound
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound9.2K views
MongoDB WiredTiger Internals: Journey To Transactions by Mydbops
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
Mydbops2.4K views
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver] by MongoDB
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB5.4K views
MongoDB and Indexes - MUG Denver - 20160329 by Douglas Duncan
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan994 views
Introduction to MongoDB by MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
MongoDB7.2K views
How to Achieve Scale with MongoDB by MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
MongoDB11.2K views
MongoDB WiredTiger Internals by Norberto Leite
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
Norberto Leite12.7K views
Sizing Your MongoDB Cluster by MongoDB
Sizing Your MongoDB ClusterSizing Your MongoDB Cluster
Sizing Your MongoDB Cluster
MongoDB2.6K views

Similar to MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB

MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDB by
MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
432 views181 slides
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB by
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBLisa Roth, PMP
35 views215 slides
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin... by
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
392 views210 slides
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB by
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
386 views205 slides
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo... by
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...MongoDB
635 views209 slides
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB by
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
442 views209 slides

Similar to MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB(17)

MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDB by MongoDB
MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Houston 2019:Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB432 views
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB by Lisa Roth, PMP
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
Lisa Roth, PMP35 views
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin... by MongoDB
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB392 views
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB by MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB386 views
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo... by MongoDB
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...
MongoDB .local Bengaluru 2019: Tips and Tricks++ for Querying and Indexing Mo...
MongoDB635 views
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB by MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB442 views
MongoDB.local Dallas 2019: Tips & Tricks for Avoiding Common Query Pitfalls by MongoDB
MongoDB.local Dallas 2019: Tips & Tricks for Avoiding Common Query PitfallsMongoDB.local Dallas 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Dallas 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB301 views
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls by MongoDB
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB101 views
Tips and Tricks for Avoiding Common Query Pitfalls by MongoDB
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB162 views
Tips and Tricks for Avoiding Common Query Pitfalls by MongoDB
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB141 views
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls by MongoDB
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB272 views
MongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls by MongoDB
MongoDB World 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB344 views
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls by MongoDB
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query PitfallsMongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB183 views
Tips and Tricks for Avoiding Common Query Pitfalls Christian Kurze by MongoDB
Tips and Tricks for Avoiding Common Query Pitfalls Christian KurzeTips and Tricks for Avoiding Common Query Pitfalls Christian Kurze
Tips and Tricks for Avoiding Common Query Pitfalls Christian Kurze
MongoDB470 views
MongoDB World 2019: How to Keep an Average API Response Time Less than 5ms wi... by MongoDB
MongoDB World 2019: How to Keep an Average API Response Time Less than 5ms wi...MongoDB World 2019: How to Keep an Average API Response Time Less than 5ms wi...
MongoDB World 2019: How to Keep an Average API Response Time Less than 5ms wi...
MongoDB408 views
import sys sys.path.append(aima-python) from search import .pdf by maheshkumar12354
import sys sys.path.append(aima-python) from search import .pdfimport sys sys.path.append(aima-python) from search import .pdf
import sys sys.path.append(aima-python) from search import .pdf

More from MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas by
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
6.6K views46 slides
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts! by
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
1.2K views20 slides
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel... by
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
1.1K views40 slides
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB by
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
1.4K views106 slides
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T... by
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
782 views37 slides
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data by
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
870 views47 slides

More from MongoDB(20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas by MongoDB
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB6.6K views
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts! by MongoDB
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB1.2K views
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel... by MongoDB
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB1.1K views
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB by MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB1.4K views
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T... by MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB782 views
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data by MongoDB
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB870 views
MongoDB SoCal 2020: MongoDB Atlas Jump Start by MongoDB
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB633 views
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys] by MongoDB
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB528 views
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2 by MongoDB
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB473 views
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ... by MongoDB
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB492 views
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts! by MongoDB
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB355 views
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset by MongoDB
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB383 views
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart by MongoDB
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB287 views
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++ by MongoDB
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB359 views
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo... by MongoDB
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB382 views
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive by MongoDB
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB330 views
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang by MongoDB
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB293 views
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app... by MongoDB
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB328 views
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning... by MongoDB
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB312 views
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB by MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB293 views

Recently uploaded

Java Platform Approach 1.0 - Picnic Meetup by
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic MeetupRick Ossendrijver
25 views39 slides
Photowave Presentation Slides - 11.8.23.pptx by
Photowave Presentation Slides - 11.8.23.pptxPhotowave Presentation Slides - 11.8.23.pptx
Photowave Presentation Slides - 11.8.23.pptxCXL Forum
126 views16 slides
Astera Labs: Intelligent Connectivity for Cloud and AI Infrastructure by
Astera Labs:  Intelligent Connectivity for Cloud and AI InfrastructureAstera Labs:  Intelligent Connectivity for Cloud and AI Infrastructure
Astera Labs: Intelligent Connectivity for Cloud and AI InfrastructureCXL Forum
125 views16 slides
Microchip: CXL Use Cases and Enabling Ecosystem by
Microchip: CXL Use Cases and Enabling EcosystemMicrochip: CXL Use Cases and Enabling Ecosystem
Microchip: CXL Use Cases and Enabling EcosystemCXL Forum
129 views12 slides
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa... by
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...The Digital Insurer
28 views18 slides
Micron CXL product and architecture update by
Micron CXL product and architecture updateMicron CXL product and architecture update
Micron CXL product and architecture updateCXL Forum
27 views7 slides

Recently uploaded(20)

Photowave Presentation Slides - 11.8.23.pptx by CXL Forum
Photowave Presentation Slides - 11.8.23.pptxPhotowave Presentation Slides - 11.8.23.pptx
Photowave Presentation Slides - 11.8.23.pptx
CXL Forum126 views
Astera Labs: Intelligent Connectivity for Cloud and AI Infrastructure by CXL Forum
Astera Labs:  Intelligent Connectivity for Cloud and AI InfrastructureAstera Labs:  Intelligent Connectivity for Cloud and AI Infrastructure
Astera Labs: Intelligent Connectivity for Cloud and AI Infrastructure
CXL Forum125 views
Microchip: CXL Use Cases and Enabling Ecosystem by CXL Forum
Microchip: CXL Use Cases and Enabling EcosystemMicrochip: CXL Use Cases and Enabling Ecosystem
Microchip: CXL Use Cases and Enabling Ecosystem
CXL Forum129 views
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa... by The Digital Insurer
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...
Micron CXL product and architecture update by CXL Forum
Micron CXL product and architecture updateMicron CXL product and architecture update
Micron CXL product and architecture update
CXL Forum27 views
CXL at OCP by CXL Forum
CXL at OCPCXL at OCP
CXL at OCP
CXL Forum208 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet52 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs168 views
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy by Fwdays
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
Fwdays40 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
TE Connectivity: Card Edge Interconnects by CXL Forum
TE Connectivity: Card Edge InterconnectsTE Connectivity: Card Edge Interconnects
TE Connectivity: Card Edge Interconnects
CXL Forum96 views
JCon Live 2023 - Lice coding some integration problems by Bernd Ruecker
JCon Live 2023 - Lice coding some integration problemsJCon Live 2023 - Lice coding some integration problems
JCon Live 2023 - Lice coding some integration problems
Bernd Ruecker67 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10165 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS39 views
Liqid: Composable CXL Preview by CXL Forum
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum121 views

MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB

  • 1. Chris Harris Tips and Tricks++ for Querying MongoDB
  • 2. Chris Harris Lead Technical Expert for Queries and Indexing
  • 4. Introductions I identified slow queries. What index do I make?
  • 5. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 6. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 8. E – S - R The ordering of index keys in a compound index is critically important. E-S-R provides guidance that is useful in most cases: • Equality first • Sort next • Range last
  • 9. E – S - R The ordering of index keys in a compound index is critically important. E-S-R provides guidance that is useful in most cases: • Equality first • Sort next • Range last What is the difference between Equality and Range?
  • 10. Definitions Equality Fields An exact match on a single value. For example: • {x:123} • {x:{$eq:123}} • {x:"123"} • {"x.y":123}
  • 11. Definitions Equality Fields An exact match on a single value. For example: • {x:123} • {x:{$eq:123}} • {x:"123"} • {"x.y":123} Sort The (entire) requested sort. .sort({x:1, y:-1})
  • 12. Definitions Equality Fields An exact match on a single value. For example: • {x:123} • {x:{$eq:123}} • {x:"123"} • {"x.y":123} Sort The (entire) requested sort. .sort({x:1, y:-1}) Range Predicates Any predicates that are not exact matches. Some operators include: • {x:{$gt:0}} • {x:{$lte:1000}}
  • 13. Equality Equality keys are placed first in any order If present in the query shape, equality fields should always form the prefix for the index. db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
  • 14. Equality Equality keys are placed first in any order If present in the query shape, equality fields should always form the prefix for the index. db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
  • 15. Equality db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {gamertag: "Ace", score: 100} {gamertag: "Ace", score: 99,999} {gamertag: "Bob", score: 15,000} {gamertag: "Bob", score: 50,000}
  • 16. Equality db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {}{} 100 15,000 50,000 99,999 Ace Bob Bob Ace {gamertag: "Ace", score: 100} {gamertag: "Ace", score: 99,999} {gamertag: "Bob", score: 15,000} {gamertag: "Bob", score: 50,000}
  • 17. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 18. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 19. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 20. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 21. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 22. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 23. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 24. Equality 100 15,000 50,000 99,999 Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 25. Equality Ace Bob Bob Ace db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) 100 99,999 15,000 50,000 {} {} {} {}
  • 26. Equality 100 Ace Bob 99,999 15,000 50,000 db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 27. Equality 100 Ace Bob 99,999 15,000 50,000 db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 28. Equality 100 Ace Bob 99,999 15,000 50,000 db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) {} {} {} {}
  • 29. Equality before Range db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) R E R E
  • 30. Sort Sort fields are placed next Placing sort predicates after sequential equality keys allow for the index to: • Provide a non-blocking sort. • Minimize the amount of scanning required. db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
  • 31. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 32. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 33. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) {} 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {} {}
  • 34. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {} 100
  • 35. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 36. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 37. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 38. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 39. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 40. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 41. Sort db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) 100 15,000 50,000 99,999 Ace Bob Bob Ace {} {}{} {}
  • 42. Sort Ace Bob Bob Ace 100 99,999 15,000 50,000 {} {} {} {} db.games.find( {gamertag: "Ace"} ).sort( {score: 1} )
  • 43. Sort 100 Ace Bob {} 99,999 15,000 50,000 {} {} db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) {}
  • 44. Sort 100 Ace Bob {} 99,999 15,000 50,000 {} {} db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) {}
  • 45. Sort 100 Ace Bob {} 99,999 15,000 50,000 {} {} db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) {}
  • 46. Sort 100 Ace Bob {} 99,999 15,000 50,000 {} {} db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) {}
  • 47. Sort after Equality db.games.find( {gamertag: "Ace"} ).sort( {score: 1} ) S E S E
  • 48. Range Range fields are usually last Generally range predicates should be placed last. This allows them to still participate in filtering the data, but does not force a blocking sort. db.games.find( {gamertag: "Ace", score: {$gt: 9000}} )
  • 49. Range after Equality db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) R E R E
  • 50. Range db.games.find( {gamertag: "Ace", score: {$gt: 9000}} ) Should range come after sort too? R E R E
  • 51. Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) Should range come after sort too? R E R E
  • 52. Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) 100 15,000 50,000 99,999 Ace Bob Cali Ace {} {}{} {}
  • 53. Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) 100 15,000 50,000 99,999 Ace Bob Cali Ace {} {}{} {}{1}{3}{2}
  • 54. {1}{3}{2} Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) 100 15,000 50,000 99,999 Ace Bob Cali Ace {}
  • 55. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 56. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 57. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 58. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 59. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 60. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 61. {1}{3}{2} Range 100 15,000 50,000 99,999 Ace Bob Cali Ace {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 62. {1}{3}{2} Range {} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 63. {1}{3}{2} Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) Blocking SortBlocking Sort BS
  • 64. {1}{3}{2} Range db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) BS
  • 65. Range 100 15,000 50,000 99,999 Ace Bob Cali Ace db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 66. Range Ace Bob Cali Ace 100 15,000 50,00099,999 {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 67. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 68. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 69. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 70. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 71. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 72. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 73. Range 100 15,000 50,00099,999 Ace Bob Cali {1} {3}{2}{} db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1})
  • 74. Range after Sort db.games.find( {score: {$gt: 9000}} ).sort({gamertag: 1}) BS R S R S
  • 75. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 76. Predicate Type Check What are the types of the following operators?
  • 77. Predicate Type Check - Inequality Inequality operators, such as the following, are E, S, or R? § $ne:123 § $nin:[1,2] Range!
  • 78. Predicate Type Check - Inequality Inequality operators, such as the following, are E, S, or R? § $ne:123 § $nin:[1,2] Range! How do you know?
  • 79. Predicate Type Check - Inequality Inequality operators, such as the following, are E, S, or R? § $ne:123 § $nin:[1,2] Range! "indexBounds" : { "x" : [ "[MinKey, 123.0)", "(123.0, MaxKey]" ] }
  • 80. Predicate Type Check - Inequality Range! "indexBounds" : { "x" : [ "[MinKey, 123.0)", "(123.0, MaxKey]" ] } 50 123 999
  • 81. Predicate Type Check - Inequality Range! "indexBounds" : { "x" : [ "[MinKey, 123.0)", "(123.0, MaxKey]" ] } 50 123 999
  • 82. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range!
  • 83. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range!
  • 84. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! planecar racecar
  • 85. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! planecar racecar
  • 86. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! planecar racecar
  • 87. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range!
  • 88. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! raincarry Carpool
  • 89. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! raincarry Carpool
  • 90. Predicate Type Check - Regex Regex operators, such as the following, are E, S, or R? § {str:/car/} § {str:/^car/i} Range! raincarry Carpool
  • 91. Predicate Type Check - $in $in filters, as demonstrated below, are E, S, or R? § {field:{$in:[1,3]}} … it depends! Can be Equality or Range in terms of the key ordering
  • 92. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D
  • 93. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D
  • 94. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D
  • 95. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D
  • 96. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D
  • 97. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D BS
  • 98. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]", "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] }
  • 99. Predicate Type Check - $in {field:{$in:[1,3]}}
  • 100. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D {} {} {} {} {} {}
  • 101. Predicate Type Check - $in 1 2 3 C G B F A D 1 2 3 C G B F A D {} {} {} {} {} {} {} {} {} {} {} {} {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } "indexBounds" : { "field" : [ "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] }
  • 102. Predicate Type Check - $in {field:{$in:[1,3]}} "indexBounds" : { "field" : [ "[1.0, 1.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } "indexBounds" : { "field" : [ "[3.0, 3.0]" ], "sortField" : [ "[MinKey, MaxKey]" ] } 1 2 3 C G B F A D 1 2 3 C G B F A D Sort Merge {} {} {} {} {} {} {} {} {} {} {} {}
  • 103. Predicate Type Check - $in BS Depends on the length of the $in list S M
  • 104. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 105. Sequential Equality Keys Does it matter if there is missing predicate in the equality key list? For example, given: § Query: {gamertag:"Ace", game: "Halo"} § Index: {gamertag:1, date:1, game:1} Is that index as efficient as the following one? {gamertag:1, game:1, date:1}
  • 106. Sequential Equality Keys Answer: It depends! … but probably not "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 107. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 108. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 109. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 110. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 111. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 112. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 113. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 114. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 115. Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 116. "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "game" : [ "["Halo", "Halo"]" ] } Sequential Equality Keys Ace Mario Halo 2016 2017 Mario Halo 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 117. Halo Sequential Equality Keys Ace Mario Halo 2016 2017 Mario 2018 2019 "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "date" : [ "[MinKey, MaxKey]" ], "game" : [ "["Halo", "Halo"]" ] } "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "game" : [ "["Halo", "Halo"]" ] }
  • 118. "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "game" : [ "["Halo", "Halo"]" ] } "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "game" : [ "["Halo", "Halo"]" ] } "indexBounds" : { "gamertag" : [ "["Ace", "Ace"]" ], "game" : [ "["Halo", "Halo"]" ], "date" : [ "[MinKey, MaxKey]" ] } Sequential Equality Keys Ace 2016 2017Mario2018 2019Halo
  • 120. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 121. Exceptions Is this "rule" always optimal? Not always. db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1})
  • 123. Exceptions Ace 1 5,000 9,0012 9,000 … … 2001 2000 2015 2019 2019 db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1})
  • 134. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace 1 5,000 9,0012 9,000 … … 2001 2000 2015 2019 2019 "executionStats" : { "nReturned" : 2, "executionTimeMillis" : 23, "totalKeysExamined" : 9001, "totalDocsExamined" : 2,
  • 136. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace 2001 2000 2015 2019 2019 {score:2} {score:1} {score:5000} {score:9001} {score:9000} … …
  • 137. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace … … 2000 2001 2015 2019 2019 {score:2} {score:1} {score:5000} {score:9001} {score:9000}
  • 138. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace … … 2000 2001 2015 2019 2019 {score:2} {score:1} {score:5000} {score:9001} {score:9000}
  • 139. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace … … 2000 2001 2015 2019 2019 {score:2} {score:1} {score:5000} {score:9001} {score:9000} BS "executionStats" : { "nReturned" : 2, "executionTimeMillis" : 0, "totalKeysExamined" : 2, "totalDocsExamined" : 2,
  • 140. Exceptions db.games .find({gamertag:"Ace", date:{$gte:2019}}) .sort({score:1}) Ace … … 2000 2001 2015 2019 2019 {score:2} {score:1} {score:5000} "executionStats" : { "nReturned" : 2, "executionTimeMillis" : 0, "totalKeysExamined" : 2, "totalDocsExamined" : 2, "executionStages" : { "stage" : "SORT", "memUsage" : 154, "memLimit" : 33554432, {score:9001}{score:9000} BS
  • 142. E-S-R Guidance A good starting place applicable to most use cases Place keys in the following order: • Equality first • Sort next • Range last Remember that equality is an exact match of a single value
  • 143. E-S-R Guidance A good starting place applicable to most use cases Place keys in the following order: • Equality first • Sort next • Range last Remember that equality is an exact match of a single value I see isMultiKey:true in the explain output. What does that mean?
  • 144. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 145. Multikey Index A special type of index which supports efficient querying for array fields
  • 146. Index Nomenclature Single Field Index The index entries reference a single field in the document Can be Multikey Compound Index The index entries reference more than one field in the document Can be Multikey Multikey Index There is separate entry in the index for every array in the document
  • 147. Single Field Index Ace Doyen { gamertag: "Ace", games:["Mario", "Halo"] } { gamertag: "Doyen", games:["Fortnite", "GTA", "Minecraft"] }{} {}
  • 148. Single Field Index - Multikey {} {} MarioHaloGTAFortnite Minecraft
  • 149. DoyenAce Compound Index - Multikey {} {} MarioHaloGTAFortnite Minecraft
  • 150. Compound Index - Multikey HaloMinecraftGTAFortnite Mario AceDoyen {}{} We tried to use arrays but get incorrect results and queries are slow. What gives?
  • 151. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 152. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] }
  • 153. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] }
  • 154. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] }
  • 155. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 156. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 157. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 158. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions
  • 159. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions."
  • 160. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 161. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 162. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 163. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 164. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 165. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 166. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 167. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 168. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 169. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 170. Semantics { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } { _id: 3, players: [ { name: "Doyen", rank : 1 }, { name: "Cali", rank : 2 } ] } "You can specify the query such that either a single array element meets these conditions or any combination of array elements meets the conditions." db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 171. Semantics - $elemMatch { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } db.matches.find({ "players.name": "Ace", "players.rank": 1 })
  • 172. Semantics - $elemMatch { _id: 1, players: [ { name: "Doyen", rank : 1 }, { name: "Ace", rank : 2 } ] } { _id: 2, players: [ { name: "Ace", rank : 1 }, { name: "Doyen", rank : 2 } ] } db.matches.find({ "players.name": "Ace", "players.rank": 1 }) db.matches.find({ "players": { $elemMatch: { name: "Ace", "rank": 1} } })
  • 173. Semantics - $elemMatch Use $elemMatch to query multiple fields of a single array element Not necessary when querying on a single predicate
  • 174. Semantics - $elemMatch Use $elemMatch to query multiple fields of a single array element Not necessary when querying on a single predicate Okay, that change got us correct results. But what about the performance?
  • 175. Roadmap § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 176. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") }
  • 177. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") } db.matches.find({ players:"Ace", date:{ $gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28") } })
  • 178. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") } db.matches.find({ players:"Ace", date:{ $gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28") } }) .explain() … "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "(true, new Date(1551312000000)]" ] }
  • 179. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") } db.matches.find({ players:"Ace", date:{ $gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28") } }) .explain() … "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "(true, new Date(1551312000000)]" ] }
  • 180. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") } db.matches.find({ players:"Ace", date:{ $gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28") } }) .explain() … "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "(true, new Date(1551312000000)]" ] }
  • 181. Multikey Path Tracking { "_id" : 1, "game" : "Halo", "players" : [ "Ace", "Doyen", "Cali", "Bob" ], "date" : ISODate("2019-02-15T00:00:00Z") } db.matches.find({ players:"Ace", date:{ $gte:ISODate("2019-02-01"), $lte:ISODate("2019-02-28") } }) .explain() … "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "(true, new Date(1551312000000)]" ] }
  • 182. Multikey Path Tracking Before MongoDB 3.4: § Database only contained coarse isMultiKey flag for index § Did not know which field was the array § Conservative behavior to ensure correct results
  • 183. Multikey Path Tracking Before MongoDB 3.4: "stage" : "IXSCAN", "indexName" : "players_1_date_1", "isMultiKey" : true, "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "(true, new Date(1551312000000)]" ] } 3.4+: ... "multiKeyPaths" : { "players" : [ "players" ], "date" : [ ] }, "indexBounds" : { "players" : [ "["Ace", "Ace"]" ], "date" : [ "[new Date(1548979200000), new Date(1551312000000)]" ] }
  • 184. Multikey Path Tracking Take advantage of the improvement § Index needs to be rebuilt when running 3.4 binaries § Just running on 3.4 is not sufficient § Look for multiKeyPaths field in explain output § v:2 index would be a deterministic check § Multikey index cannot cover queries on the array field
  • 185. Multikey Path Tracking Take advantage of the improvement § Index needs to be rebuilt when running 3.4 binaries § Just running on 3.4 is not sufficient § Look for multiKeyPaths field in explain output § v:2 index would be a deterministic check § Multikey index cannot cover queries on the array field Wow! Everything is running at Web Scale now!
  • 187. § E-S-R § Overview § Predicate Type Check § Sequential Prefix § Exceptions? § Multikey Index § Definition § Semantics § Performance
  • 190. Key Ordering Resources Blog Post My colleague Jesse wrote an article which explores the performance characteristics of different arrangements. MongoDB University My colleague Kirby covers many indexing topics in greater detail, including key ordering, in M201: MongoDB Performance.
  • 191. Please provide Session Feedback 1. Go to slido.com 2. Enter event code #MDBW19 3. Click on Room Name and Provide Session Feedback Feedback poll will remain open for 10 minutes after the talk ends Questions? Meet me now in the Leaf Lounge on the second floor of the Partner Pavilion YOU ARE IN MURRAY HILL