14

Click here to load reader

Introduction to MongoDB for C# developers

Embed Size (px)

Citation preview

Page 1: Introduction to MongoDB for C# developers

Introduction to MongoDB

for C# developers

by Taras Romanyk – [email protected]://www.linkedin.com/in/rredcat

Page 2: Introduction to MongoDB for C# developers

What is it?

● Document

● Open source

● High performance

● Horizontally scalable

Page 3: Introduction to MongoDB for C# developers

Terminology

RDBMS MongoDB

Table, View Collection

Row Document

Index Index

Join Embedded Document

Foreign Key Reference

Partition Shard

Page 4: Introduction to MongoDB for C# developers

What is it?

BSON{

"_id": ObjectId("4efa8d2b7d284dad101e4bc7"),

"Last Name": "PELLERIN","First Name": "Franck","Date of Birth": "09-19-1983","Address": "1 chemin des Loges","City": "VERSAILLES"

}

Page 5: Introduction to MongoDB for C# developers

CRUD

● 16 MB limitation

● GridFS (chunks, files) partly loading

● $inc, $mul, $rename, $setOnInsert,

$set,$unset, $min, $max, $currentDate

{ _id: 1, highScore: 800, lowScore: 200 }

Page 6: Introduction to MongoDB for C# developers

CRUD

{ _id: 1, highScore: 800, lowScore: 200 }

db.scores.update(

{ _id: 1 },

{ $min: { lowScore: 150 } }

)

{ _id: 1, highScore: 800, lowScore: 200 }

Page 7: Introduction to MongoDB for C# developers

Find/Aggregation

Find

db.inventory.find( { type: 'food', price: { $lt: 9.95 } } )

Aggregation

$project, $match, $limit, $skip, $unwind,

$group, $sort, $geoNear, $out, $redact

$out

$out

Page 8: Introduction to MongoDB for C# developers

Find/Aggregation

{"_id": "10", "city": "NEW YORK", "state": "NY", "pop": 5574}

db.zipcodes.aggregate( { $group :{

_id : { state : "$state", city : "$city" },pop : { $sum : "$pop" } } },

{ $group : {_id : "$_id.state",avgCityPop : { $avg : "$pop" }

} } )

Page 9: Introduction to MongoDB for C# developers

MapReduce

var map ="function() {" +" for (var key in this) {" +" emit(key, { count : 1 });" +" }" +"}";

var reduce ="function(key, emits) {" +" total = 0;" +" for (var i in emits) {" +" total += emits[i].count;" +" }" +" return { count : total };" +"}";

var mr = collection.MapReduce(map, reduce);foreach (var document in mr.GetResults()) {

Console.WriteLine(document.ToJson());}

Page 10: Introduction to MongoDB for C# developers

Exmaple

Page 11: Introduction to MongoDB for C# developers

Example

Page 12: Introduction to MongoDB for C# developers

Example

Page 13: Introduction to MongoDB for C# developers

Example

Page 14: Introduction to MongoDB for C# developers

Q&A

https://university.mongodb.com/courseshttp://docs.mongodb.org/manual/

http://www.10gen.com/presentationshttps://groups.google.com/forum/#!forum/mongodb-userhttp://stackoverflow.com/questions/tagged/mongodbhttp://robomongo.org/