Slide 1

Slide 1 text

Exploring design patterns with MongoDB TAMING THE HORSEPOWERS Morten Holk Maate Sr. Developer, Product Manager [email protected]

Slide 2

Slide 2 text

db.GetCollection(''Employee'').Save(employee);

Slide 3

Slide 3 text

One reason that MongoDB is great is that our data store uses objects – as well as our OO programming language uses objects JSON in Mongo Shell: C# in Visual Studio:

Slide 4

Slide 4 text

… and objects do seem like a great abstraction for … objects

Slide 5

Slide 5 text

MongoDB Solves The Object-Relational Impedence Mismatch • Data Mapping • Normalization • Object Identity • Serialization Storing Objects as Objects Utilizing Object Hierarkies With ObjectId() As BSON

Slide 6

Slide 6 text

Your Object is not your Object! Is NOT equal to this: And this:

Slide 7

Slide 7 text

Literally 

Slide 8

Slide 8 text

EXPECTATIONS • Data Mapping • Normalization • Object Identity • Serialization REALITY • C#/Java objects still needs some mapping to become Mongo Objects • C#/Java objects still needs some normalization • We have not solved the identity problem • Serialization still is not easy

Slide 9

Slide 9 text

Hands on case: Storing employees in a database Take 1 Illustrating the Challenges

Slide 10

Slide 10 text

Main Procedure • Create object instance • Store object • Load object SalesEmployee + Id : ObjectId + Name : String + Value : Int32 Mongo DB

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

db.GetCollection(''Employee'').Save(employee); Won’t build without MongoDB Reference

Slide 13

Slide 13 text

Won’t build without MongoDB Reference

Slide 14

Slide 14 text

Hands on case: Storing employees in a database Take 2 ”ActiveRecord Pattern”

Slide 15

Slide 15 text

Main Procedure • Create object instance • Store object • Load object SalesEmployee + Id : ObjectId + Name : String + Value : Int32 + Save() + Load() Mongo DB Active Record I

Slide 16

Slide 16 text

Main Procedure • Create object instance • Store object • Load object PersistentObject + ObjectId + void Save(T obj) + T Load(ObjectId id) SalesEmployee + Name : String + Value : Int32 Mongo DB DataAccess Domain Active Record II

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Hands on case: Storing employees in a database Take 3 ”Repository Pattern”

Slide 19

Slide 19 text

Main Procedure • Create object instance • Store object • Load object Employee + Name : String + Value : Int32 Repository + void Save(T obj) + T Load(ObjectId id) IRepository + Load() + Save() Sales Employee Developer Mongo DB DataAccess Domain Repository Pattern PersistentObject + ObjectId

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Hands on case: Storing employees in a database Take 4 ”DataMapper pattern”

Slide 22

Slide 22 text

Main Procedure • Map Data • Create object instance • Store object • Load object Employee + Id : String + Name : String + Value : Int32 Repository + void Save(T obj) + T Load(String id) IRepository + Load() + Save() Sales Employee Developer Mongo DB DataAccess Domain Settings + SetupDatabase() DataMapping DataMapper

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Hands on case: Storing employees in a database Take 5 ”DataMapper pattern II”

Slide 25

Slide 25 text

Main Procedure • Create object instance • Store object • Load object Employee + Id : String + Name : String + Value : Int32 Repository + void Save(T obj) + T Load(String id) Employee Repository IRepository + Load() + Save() Sales Employee Developer +BestFriend : Developer Developer Repository Developer Repository Mongo DB DataAccess Domain DataMapper Pattern

Slide 26

Slide 26 text

No content