@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Flexible schema
Application driven-schema
Rich document
Pre join / Embed document
No mongo join
No constraints
No transactions
Atomicity
@sensiolabs sensiolabs.com
users
{
_id: "joe",
name: "Joe Bookreader"
}
addresses
{
user_id: "joe",
street: "123 Fake Street",
city: "Faketon",
state: "MA",
zip: "12345"
}
@sensiolabs sensiolabs.com
users
{
_id: "joe",
name: "Joe Bookreader",
address: {
street: "123 Fake Street",
city: "Faketon",
state: "MA"
}
}
Frequency of access
Document Growth
Atomicity
@sensiolabs sensiolabs.com
cities
{
name: "Paris",
region: "IDF",
people: [
...
]
}
Too many people...
@sensiolabs sensiolabs.com
Duplication of data = inconsistency
people
{
name: "Joe",
city: {
name: "Paris",
region: "IDF"
}
}
people
{
name: "Jane",
city: {
name: "Paris",
region: "IDF"
}
}
@sensiolabs sensiolabs.com
Make sure the city exist (no foreign key)
people
{
name: "Joe",
city: "Paris"
}
cities
{
_id: "Paris",
region: "IDF"
}
Multiple queries
@sensiolabs sensiolabs.com
No data inconsistency
people
{
name: "Joe",
addresses: [
{...},
{...},
{...}
]
}
@sensiolabs sensiolabs.com
What is the cardinality of the relationship ?
One to many => referencing
One to few => embedding
@sensiolabs sensiolabs.com
Use multikey indexes for performance
students
{
_id: 0,
name: 'joe',
teachers: [2, 11, 41]
}
teachers
{
_id: 11,
name: 'John',
students: [...]
}
Use reference
@sensiolabs sensiolabs.com
Find the descendants and the ancestors of a node
Array of ancestors
ancestors: [ "Books", "Programming", "Databases" ]
ancestors: [ "Books", "Programming" ]
ancestors: [ "Books" ]
ancestors: [ ]
@sensiolabs sensiolabs.com
JSON schema validation since MongoDB 3.6
db.createCollection("students", { validator: { $jsonSchema: { bsonType: "object", required: [ "name", "year", "major", "gpa" ], properties: { name: { bsonType: "string", description: "must be a string and is required" }, ... } } } })
@sensiolabs sensiolabs.com
MongoDB 4.0 will support Multi-Document ACID Transactions
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Single Purpose Aggregation Operations
Aggregation Pipeline
Map-Reduce
@sensiolabs sensiolabs.com
count
distinct
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Un Framework pour effectuer des analyses ou statistiques et générer des rapports pré-agrégés
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Map Reduce opération sous stéroïde
Limitation à 16MB d'output en BSON
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Un noeud Primary
Transparent pour le développeur
Toutes les opérations se font par défaut sur le Primary
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
Si un noeud Primaire ne réponds pas pendant 10s un autre noeud prendra sa place
Election - scrutin majoritaire - pour élire un nouveau noeud primaire
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
sh.shardCollection("db.articles", {name: "hashed"})
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
@sensiolabs sensiolabs.com
updateOne(), removeOne(), deleteOne()
@sensiolabs sensiolabs.com