ever ything you know about mongodb is wrong...mongodb is wrong (probably) mark smith | mongodb |...

40
Everything You Know About MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K

Upload: others

Post on 16-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Everything You Know About MongoDB is Wrong

(Probably)

Mark Smith | MongoDB | @Judy2K

Page 2: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

You think we haven’t seen this on YouTube

Myth 0

@Gar1t on YouTube

Page 3: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

We’ve seen it.

We’ve bought the T-shirts.

MongoDB is Web Scale

Page 4: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

What is MongoDB?

Page 5: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Database Cluster

Primary

SecondarySecondary

Page 6: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

DocumentsDatabase Cluster

Primary

SecondarySecondary

{'_id': ObjectId('573a1390f29313caabcd4135'), 'title': 'Blacksmith Scene', 'fullplot': 'A stationary camera looks at a large anvil with a blacksmith behind it and one on either side.', 'cast': ['Charles Kayser', 'John Ott'], 'countries': ['USA'], 'directors': ['William K.L. Dickson'], 'genres': ['Short'], 'imdb': {'id': 5, 'rating': 6.2, 'votes': 1189}, 'released': datetime.datetime(1893, 5, 9, 0, 0), 'runtime': 1, 'year': 1893}

Page 7: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

DocumentsDatabase Cluster

Primary

SecondarySecondary

{'_id': ObjectId('573a1390f29313caabcd4135'), 'title': 'Blacksmith Scene', 'fullplot': 'A stationary camera looks at a large anvil with a blacksmith behind it and one on either side.', 'cast': ['Charles Kayser', 'John Ott'], 'countries': ['USA'], 'directors': ['William K.L. Dickson'], 'genres': ['Short'], 'imdb': {'id': 5, 'rating': 6.2, 'votes': 1189}, 'released': datetime.datetime(1893, 5, 9, 0, 0), 'runtime': 1, 'year': 1893}

Page 8: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

DocumentsDatabase Cluster

Primary

SecondarySecondary

{'_id': ObjectId('573a1390f29313caabcd4135'), 'title': 'Blacksmith Scene', 'fullplot': 'A stationary camera looks at a large anvil with a blacksmith behind it and one on either side.', 'cast': ['Charles Kayser', 'John Ott'], 'countries': ['USA'], 'directors': ['William K.L. Dickson'], 'genres': ['Short'], 'imdb': {'id': 5, 'rating': 6.2, 'votes': 1189}, 'released': datetime.datetime(1893, 5, 9, 0, 0), 'runtime': 1, 'year': 1893}

Page 9: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

$ sudo apt install mongodb$ mongod --versiondb version v2.4

MongoDB is v2.4

Myth 1

Page 10: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Google mongodb community

MongoDB is v4.4

Page 11: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

MongoDB is a document database

The JSON database

Myth 2

Page 12: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve
Page 13: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

MongoDB is a document database

The BSON database

Page 14: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

MongoDB is a BASE database

No Transactions

Myth 3

Page 15: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

MongoDB is an ACID database

Yes Transactions

Page 16: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

You can’t have relationships between documents.

No Relationships

Myth 4

Page 17: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

You totally can.

Yes Relationships

Page 18: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

An Aggregation Pipeline

db.orders.aggregate([{ $lookup: {

from: "inventory",

localField: "item",

foreignField: "sku",

as: "inventory_docs"

}

}])

Page 19: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

An Aggregation Pipeline

{

"_id" : 1,

"item" : "almonds",

"price" : 12,

"quantity" : 2,

"inventory_docs" : [

{ "_id" : 1, "sku" : "almonds", "instock" : 120 }

]

}

Page 20: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

A Very Simple Aggregation Pipeline

{

"_id" : 1,

"item" : "almonds",

"price" : 12,

"quantity" : 2,

"inventory_docs" : [

{ "_id" : 1, "sku" : "almonds", "instock" : 120 }

]

}

Page 21: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

That’s how you scale

MongoDB is About Sharding

Myth 5

Page 22: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Quick Sharding Primer - 2 shards

SecondarySecondary SecondarySecondary

Shard Server Shard Server

Primary Primary

Page 23: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

MongoDB can do sharding,but you probably shouldn’t

Just Buy a Bigger Machine

Page 24: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

We will host your database for you

Actually, use Atlas

Page 25: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

… isn't a thing any more

Microsharding

Page 26: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

… with JavaScript.

Map-Reduce

Page 27: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve
Page 28: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Aggregation Pipelines

Page 29: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

A Very Simple Aggregation Pipeline

db.orders.aggregate([

{ $match: { status: "A" } },

{ $group: { _id: "$cust_id", total: { $sum: "$amount" }}}

])

Page 30: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

A Very Simple Aggregation Pipeline

db.orders.aggregate([

{ $match: { status: "A" } },

{ $group: { _id: "$cust_id", total: { $sum: "$amount" }}}

])

Page 31: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

A Very Simple Aggregation Pipeline

db.orders.aggregate([

{ $match: { status: "A" } },

{ $group: { _id: "$cust_id", total: { $sum: "$amount" }}}

])

Page 32: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Haven’t there been breaches?

MongoDB is Insecure

Myth 6

Page 33: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Industry-standard security.Bad defaults have been fixed.

MongoDB is Secure

Page 34: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

… doesn’t it?

MongoDB Loses Data

Myth 7

Page 35: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

… but we used to have some silly defaults

MongoDB Is Durable

Page 36: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Primary

SecondarySecondary

Database Cluster

Page 37: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Well … yes … and no.

MongoDB is Really Easy

Myth 8

Page 38: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

https://bit.ly/mongodb-covid

COVID-19 Open Data

Page 39: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Everything You Know About MongoDB is Wrong

(Probably)

Mark Smith | MongoDB | @Judy2K

Some stuffRight

Page 40: Ever ything You Know About MongoDB is Wrong...MongoDB is Wrong (Probably) Mark Smith | MongoDB | @Judy2K. You think we haven’t seen this on YouTube Myth 0 @Gar1t on YouTube. We’ve

Thank youThat’s all folks

Mark Smith | MongoDB | @Judy2k