Introduction to MongoDB for C# developers

Preview:

Citation preview

Introduction to MongoDB

for C# developers

by Taras Romanyk – rredcat@gmail.comhttp://www.linkedin.com/in/rredcat

What is it?

● Document

● Open source

● High performance

● Horizontally scalable

Terminology

RDBMS MongoDB

Table, View Collection

Row Document

Index Index

Join Embedded Document

Foreign Key Reference

Partition Shard

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"

}

CRUD

● 16 MB limitation

● GridFS (chunks, files) partly loading

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

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

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

CRUD

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

db.scores.update(

{ _id: 1 },

{ $min: { lowScore: 150 } }

)

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

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

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" }

} } )

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());}

Exmaple

Example

Example

Example

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/

Recommended