SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Downloaden Sie, um offline zu lesen
MongoDB for C# Developers
Simon Elliston Ball
Head of Big Data
!

@sireb
!
!
!
!
http://www.mongodb.org/
Document Database
Document Database
id

full_name

address

1

John Smith

3a Test Street

2

Jane Doe

1b Fake Street

3

...

...
Document Database
id

full_name

address

1

John Smith

3a Test Street

2

Jane Doe

1b Fake Street

3

...

...

1

customer_i
d
1

...

2

1

...

order_date
2013-10-1
0
...

3

...

...

...

id
Document Database
id

full_name

address

1

John Smith

3a Test Street

2

Jane Doe

1b Fake Street

id

3

...order_id

1

1

1

2
customer_i
d3
1

2

1

...

3

...

...

id

... product_id

1
......

103
order_date ...
2013-10-1 ...
0
...
...
Document Database
id

full_name

address

1

John Smith

3a Test Street

2

Jane Doe

1b Fake Street

id

customer_id
...

1

3

1

1

2
customer_i
d3
1

2

1

...

3

...

...

id

1
......

... order_date
2013-10-10

order_date ...
2013-10-1 ...
0
...
...
Document Database
id

full_name

address

1

John Smith

3a Test Street

2

Jane Doe

1b Fake Street

id

customer_id
...

1

3

1

1

2
customer_i
d3
1

2

1

...

3

...

...

id

1
......

... order_date
2013-10-10

order_date ...
2013-10-1 ...
0
...
...

customers = [
{
"_id" : ObjectId("5256b399ac46b80084974d9a"),
"name" : "John Smith",
"address" : "3a Test Street",
"orders" [ {
"order_date": "2013-10-10",
"order_item": [
{ "product": "Widget"...}
...
]
...
}]
},
{
"_id" : ObjectId("5256b3a8ac46b80084974d9b"),
"name" : "Jane Doe",
"address" : "1b Fake Street"
}
]
Key -> JSON
Document Database - Why?
Flexible Data Model - No Schema
Rapid Development
Scalability
Document Database - When?
Blogs
Document Database - When?
Content management
When read patterns are fixed
Scaling requirements are unknown
When write speed matters
•

Transactions per document

•

ACID, multi-document

•

Master-slave replication

•

But… Background Indexing

•

Many many languages: C#,

•

Master-master replication

JavaScript, Java, PHP, Python, Ruby,

•

.NET Only

Scala, Erlang, Go, C, C++, Perl (and those are just
the official ones)
•

Main interface: CLI

•

GUI Client

•

Transactions per document

•

Native JSON

•

Master-slave replication

•

Geo-aware replication

•

Many many languages: C#,

•

REST Interface, so anything

JavaScript, Java, PHP, Python, Ruby,

•

View based queries

Scala, Erlang, Go, C, C++, Perl (and those are just
the official ones)
Getting started with MongoDB
Download from http://www.mongodb.org/
Getting started with the C# client
PM> Install-Package mongocsharpdriver
Wooah there.
I thought you said JSON...
BSON Binary JSON
BSON Binary JSON
Typed
BSON Binary JSON
Typed
Serialisation library
BSON Binary JSON
Typed
Serialisation library
Annotate POCOs to control mapping
or write config code if you must
Connecting...
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
Connecting...
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();

That’s it.
The driver will disconnect,
release objects and pool for you.
!

But...
Collections
Database
Collection
Document
_id
field…
CRUD creating new documents
With mapped entities:
var developerCollection = database.GetCollection<Developer>("team");
!

var Developer = new Developer(1,"Test", "Person");
developerCollection.Insert(Developer);
var Developer2 = new Developer(2,"Another", "Developer");
developerCollection.Insert(Developer2)

The BsonDocument way:
var documentCollection = database.GetCollection("team");
!

BsonDocument document = new BsonDocument();
document.Add(new BsonElement("name", "Testing"))
.Add(new BsonElement("number", new BsonInt32(42)));
!

documentCollection.Insert(document);
CRUD creating new documents
The BsonDocument way:
var documentCollection = database.GetCollection("team");
!

BsonDocument document = new BsonDocument();
document.Add(new BsonElement("name", "Testing"))
.Add(new BsonElement("number", new BsonInt32(42)));
!

documentCollection.Insert(document);

Beware of mixing your BSONs
List<Developer> allDevelopers = developerResults.ToList<Developer>();
CRUD creating new documents
Beware of mixing your BSONs
List<Developer> allDevelopers = developerResults.ToList<Developer>();
CRUD basic document reads
MongoCursor<BsonDocument> documentResults = documentCollection.FindAll();
MongoCursor<Developer> developerResults = developerCollection.FindAll();
CRUD basic document reads
MongoCursor<BsonDocument> documentResults = documentCollection.FindAll();
MongoCursor<Developer> developerResults = developerCollection.FindAll();
var cursor = collection.FindAll();
cursor.Skip = 100;
cursor.Limit = 10;
!

foreach (var developer in cursor) {
...
CRUD basic document reads
MongoCursor<BsonDocument> documentResults = documentCollection.FindAll();
MongoCursor<Developer> developerResults = developerCollection.FindAll();
var cursor = collection.FindAll();
cursor.Skip = 100;
cursor.Limit = 10;
!

foreach (var developer in cursor) {
...
}

var readQuery = Query<Developer>.EQ(n => n.PersonId, 2);
Developer developerRead = developerCollection.FindOne(readQuery);
CRUD basic document reads
MongoCursor<BsonDocument> documentResults = documentCollection.FindAll();
MongoCursor<Developer> developerResults = developerCollection.FindAll();
var cursor = collection.FindAll();
cursor.Skip = 100;
cursor.Limit = 10;
!

foreach (var developer in cursor) {
...
}

var readQuery = Query<Developer>.EQ(n => n.PersonId, 2);
Developer developerRead = developerCollection.FindOne(readQuery);
BsonDocument documentRead = documentCollection.FindOne(new QueryDocument {
{ "_id", documentId }
});
CRUD update
developerRead.LastName = "Something-Else";
developerCollection.Save(developerRead);
CRUD update
Write Concerns
Only relevant with Replication
The number of replicas which need to report successful writes
collection.Save(developerRead, new MongoInsertOptions
{
WriteConcern = WriteConcern.WMajority
}
);
CRUD update
var update = new UpdateDocument {
{ "$set", new BsonDocument("LastName", "A new name") }
};
!

var query = new QueryDocument {
{ "LastName", "Developer" }
};
!

collection.Update(query, update);
NB. Only updates one document
CRUD update
var update = new UpdateDocument {
{ "$set", new BsonDocument("LastName", "A new name") }
};
!

var query = new QueryDocument {
{ "LastName", "Developer" }
};
!

collection.Update(query, update);
NB. Only updates one document
collection.Update(query, update, new MongoUpdateOptions
{
Flags = UpdateFlags.Multi
});
Applies to all documents that match query
CRUD upsert
var update = new UpdateDocument {
{ "$set", new BsonDocument("LastName", "A new name") }
};
var query = Query<Developer>.EQ(d => d.PersonId, 10);
!

collection.Update(query, update, new MongoUpdateOptions
{
Flags = UpdateFlags.Upsert
});
CRUD deleting
var query = new QueryDocument {
{ "LastName", "Person" }
};
collection.Remove(query);
CRUD deleting
var query = new QueryDocument {
{ "LastName", "Person" }
};
collection.Remove(query);

collection.RemoveAll();
collection.Drop();
LINQ integration
Just make the collection queryable
using System.Linq;
using MongoDB.Driver.Linq;
!

var query =
from e in collection.AsQueryable()
where e.LastName == "Person"
select e;
!

foreach (var developer in query){
...
GridFS in C#
16MB document limit
GridFS used to break documents into chunks
using (var fs = new FileStream("largeVideo.m4v", FileMode.Open))
{
database.GridFS.Upload(fs, "largeVideo.m4v");
}
database.GridFS.Download("test.m4v", "largeVideo.m4v");
MapReduce (JavaScript)
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);

Yes, it’s a word count. Yes, it’s JavaScript.
Special Queries GeoNear
var query = Query.EQ("properties.amenity", new BsonString("pub"));
// here
double lon = 54.9117468;
double lat = -1.3737675;
!

var earthRadius = 6378.0; // km
var rangeInKm = 3000.0; // km
!

var options = GeoNearOptions
.SetMaxDistance(rangeInKm / earthRadius /* to radians */)
.SetSpherical(true);
!

var results = collection.GeoNear(query, lat, lon, 10, options);
!

foreach (var result in results.Hits)
...
Aggregation Framework
Aggregation Framework
Pipeline based
Aggregation Framework
Pipeline based
Chained operators
Aggregation Framework
Pipeline based
Chained operators
$project
$match
$limit
$skip
$unwind
$group
$sort
… http://docs.mongodb.org/manual/reference/operator/aggregation/
Aggregation Framework
Demo
Summary
Document databases are simple
BSON annotation makes POCO mapping is easy
CRUD is straight forward
You can use LINQ
Hard stuff is possible
Acknowledgements
MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
Resources
The MongoDB C Sharp Language Center:

http://docs.mongodb.org/ecosystem/drivers/csharp/

A tutorial on the driver from MongoDB themselves:

http://docs.mongodb.org/ecosystem/tutorial/use-csharp-driver/#csharp-driver-tutorial

Sample code from this talk:

https://github.com/simonellistonball/MongoForCsharpSamples

A good walkthrough on MongoDB with ASP.NET MVC:

http://www.drdobbs.com/database/mongodb-with-c-deep-dive/240152181


Bonus extras
A Glimpse plugin to view mongo query details:

https://github.com/simonellistonball/Glimpse.MongoDB
Questions?
Simon Elliston Ball
simon.ellistonball@red-gate.com
!

@sireb
!
!
!

http://bit.ly/MongoForCsharp

Weitere ähnliche Inhalte

Was ist angesagt?

Basic crud operation
Basic crud operationBasic crud operation
Basic crud operationzarigatongy
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
File System Operations
File System OperationsFile System Operations
File System OperationsG.C Reddy
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Andrii Lashchenko
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLGabriela Ferrara
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityMongoDB
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkMongoDB
 
Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Precisely
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
dotSwift - From Problem to Solution
dotSwift - From Problem to SolutiondotSwift - From Problem to Solution
dotSwift - From Problem to Solutionsoroushkhanlou
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Conquering JSONB in PostgreSQL
Conquering JSONB in PostgreSQLConquering JSONB in PostgreSQL
Conquering JSONB in PostgreSQLInes Panker
 

Was ist angesagt? (19)

Basic crud operation
Basic crud operationBasic crud operation
Basic crud operation
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
File System Operations
File System OperationsFile System Operations
File System Operations
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 
Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
dotSwift - From Problem to Solution
dotSwift - From Problem to SolutiondotSwift - From Problem to Solution
dotSwift - From Problem to Solution
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Conquering JSONB in PostgreSQL
Conquering JSONB in PostgreSQLConquering JSONB in PostgreSQL
Conquering JSONB in PostgreSQL
 

Andere mochten auch

Regional Identity
Regional IdentityRegional Identity
Regional IdentityJoe Toyer
 
Power Point- Carrera de Atletismo
Power Point- Carrera de AtletismoPower Point- Carrera de Atletismo
Power Point- Carrera de Atletismogiuliicobb
 
5.2 use perpendicular bisectors
5.2 use perpendicular bisectors5.2 use perpendicular bisectors
5.2 use perpendicular bisectorsdetwilerr
 
Magazine cover analysis
Magazine cover analysisMagazine cover analysis
Magazine cover analysisBenjaminSSmith
 
Libby Brown Leopard Hoodie
Libby Brown Leopard HoodieLibby Brown Leopard Hoodie
Libby Brown Leopard HoodieVIE ACTIVE
 
Planning for BYOD and CYOD in future UCC infrastructure
Planning for BYOD and CYOD in future UCC infrastructurePlanning for BYOD and CYOD in future UCC infrastructure
Planning for BYOD and CYOD in future UCC infrastructureAnders Løkke
 
Traveling to delhi (india)
Traveling to delhi (india)  Traveling to delhi (india)
Traveling to delhi (india) Kavita Aswani
 
Excellent Fabrics Used For Compression Tights
Excellent Fabrics Used For Compression TightsExcellent Fabrics Used For Compression Tights
Excellent Fabrics Used For Compression TightsVIE ACTIVE
 
Excellent Workout Clothes For Today’s Active Women
Excellent Workout Clothes For Today’s Active WomenExcellent Workout Clothes For Today’s Active Women
Excellent Workout Clothes For Today’s Active WomenVIE ACTIVE
 
A message to_my_eye_colored_flyer_in_a_printable_form
A message to_my_eye_colored_flyer_in_a_printable_formA message to_my_eye_colored_flyer_in_a_printable_form
A message to_my_eye_colored_flyer_in_a_printable_formQalbunJameel
 
3.6 prove theorems about perpendicular lines
3.6 prove theorems about perpendicular lines3.6 prove theorems about perpendicular lines
3.6 prove theorems about perpendicular linesdetwilerr
 
Union Suisse Spring :: Co-Creation
Union Suisse Spring :: Co-CreationUnion Suisse Spring :: Co-Creation
Union Suisse Spring :: Co-CreationCatalyx
 
Power Point- Ingles- Escuela
Power Point- Ingles- EscuelaPower Point- Ingles- Escuela
Power Point- Ingles- Escuelagiuliicobb
 
2.7 prove angle pair relationships
2.7 prove angle pair relationships2.7 prove angle pair relationships
2.7 prove angle pair relationshipsdetwilerr
 

Andere mochten auch (20)

Regional Identity
Regional IdentityRegional Identity
Regional Identity
 
Gangster films
Gangster filmsGangster films
Gangster films
 
Power Point- Carrera de Atletismo
Power Point- Carrera de AtletismoPower Point- Carrera de Atletismo
Power Point- Carrera de Atletismo
 
O Sister, Remember
O Sister, Remember O Sister, Remember
O Sister, Remember
 
5.2 use perpendicular bisectors
5.2 use perpendicular bisectors5.2 use perpendicular bisectors
5.2 use perpendicular bisectors
 
Magazine cover analysis
Magazine cover analysisMagazine cover analysis
Magazine cover analysis
 
Libby Brown Leopard Hoodie
Libby Brown Leopard HoodieLibby Brown Leopard Hoodie
Libby Brown Leopard Hoodie
 
Peace Day 2014
Peace Day 2014Peace Day 2014
Peace Day 2014
 
Planning for BYOD and CYOD in future UCC infrastructure
Planning for BYOD and CYOD in future UCC infrastructurePlanning for BYOD and CYOD in future UCC infrastructure
Planning for BYOD and CYOD in future UCC infrastructure
 
Traveling to delhi (india)
Traveling to delhi (india)  Traveling to delhi (india)
Traveling to delhi (india)
 
Plane figures1
Plane figures1Plane figures1
Plane figures1
 
Excellent Fabrics Used For Compression Tights
Excellent Fabrics Used For Compression TightsExcellent Fabrics Used For Compression Tights
Excellent Fabrics Used For Compression Tights
 
Excellent Workout Clothes For Today’s Active Women
Excellent Workout Clothes For Today’s Active WomenExcellent Workout Clothes For Today’s Active Women
Excellent Workout Clothes For Today’s Active Women
 
A message to_my_eye_colored_flyer_in_a_printable_form
A message to_my_eye_colored_flyer_in_a_printable_formA message to_my_eye_colored_flyer_in_a_printable_form
A message to_my_eye_colored_flyer_in_a_printable_form
 
My Portfolio
My Portfolio My Portfolio
My Portfolio
 
3.6 prove theorems about perpendicular lines
3.6 prove theorems about perpendicular lines3.6 prove theorems about perpendicular lines
3.6 prove theorems about perpendicular lines
 
Union Suisse Spring :: Co-Creation
Union Suisse Spring :: Co-CreationUnion Suisse Spring :: Co-Creation
Union Suisse Spring :: Co-Creation
 
Power Point- Ingles- Escuela
Power Point- Ingles- EscuelaPower Point- Ingles- Escuela
Power Point- Ingles- Escuela
 
Genre history
Genre historyGenre history
Genre history
 
2.7 prove angle pair relationships
2.7 prove angle pair relationships2.7 prove angle pair relationships
2.7 prove angle pair relationships
 

Ähnlich wie NDC London 2013 - Mongo db for c# developers

San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring DataOliver Gierke
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB ApplicationJoe Drumgoole
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationMongoDB
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Tobias Trelle
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBMongoDB
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksBruno Rocha
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBWildan Maulana
 
Marc s01 e02-crud-database
Marc s01 e02-crud-databaseMarc s01 e02-crud-database
Marc s01 e02-crud-databaseMongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaMongoDB
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...MongoDB
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationJoe Drumgoole
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 

Ähnlich wie NDC London 2013 - Mongo db for c# developers (20)

San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB Application
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDB
 
MongoDB and its usage
MongoDB and its usageMongoDB and its usage
MongoDB and its usage
 
Marc s01 e02-crud-database
Marc s01 e02-crud-databaseMarc s01 e02-crud-database
Marc s01 e02-crud-database
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB Application
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 

Mehr von Simon Elliston Ball

A streaming architecture for Cyber Security - Apache Metron
A streaming architecture for Cyber Security - Apache MetronA streaming architecture for Cyber Security - Apache Metron
A streaming architecture for Cyber Security - Apache MetronSimon Elliston Ball
 
mcubed london - data science at the edge
mcubed london - data science at the edgemcubed london - data science at the edge
mcubed london - data science at the edgeSimon Elliston Ball
 
When to no sql and when to know sql javaone
When to no sql and when to know sql   javaoneWhen to no sql and when to know sql   javaone
When to no sql and when to know sql javaoneSimon Elliston Ball
 
Machine learning without the PhD - azure ml
Machine learning without the PhD - azure mlMachine learning without the PhD - azure ml
Machine learning without the PhD - azure mlSimon Elliston Ball
 
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...Simon Elliston Ball
 
Getting your Big Data on with HDInsight
Getting your Big Data on with HDInsightGetting your Big Data on with HDInsight
Getting your Big Data on with HDInsightSimon Elliston Ball
 
Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Simon Elliston Ball
 
Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Simon Elliston Ball
 
Finding and Using Big Data in your business
Finding and Using Big Data in your businessFinding and Using Big Data in your business
Finding and Using Big Data in your businessSimon Elliston Ball
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQLSimon Elliston Ball
 

Mehr von Simon Elliston Ball (10)

A streaming architecture for Cyber Security - Apache Metron
A streaming architecture for Cyber Security - Apache MetronA streaming architecture for Cyber Security - Apache Metron
A streaming architecture for Cyber Security - Apache Metron
 
mcubed london - data science at the edge
mcubed london - data science at the edgemcubed london - data science at the edge
mcubed london - data science at the edge
 
When to no sql and when to know sql javaone
When to no sql and when to know sql   javaoneWhen to no sql and when to know sql   javaone
When to no sql and when to know sql javaone
 
Machine learning without the PhD - azure ml
Machine learning without the PhD - azure mlMachine learning without the PhD - azure ml
Machine learning without the PhD - azure ml
 
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...
Why Hadoop and SQL just want to be friends - lightning talk NoSQL Matters Dub...
 
Getting your Big Data on with HDInsight
Getting your Big Data on with HDInsightGetting your Big Data on with HDInsight
Getting your Big Data on with HDInsight
 
Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0
 
Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0Riding the Elephant - Hadoop 2.0
Riding the Elephant - Hadoop 2.0
 
Finding and Using Big Data in your business
Finding and Using Big Data in your businessFinding and Using Big Data in your business
Finding and Using Big Data in your business
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQL
 

Kürzlich hochgeladen

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Kürzlich hochgeladen (20)

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

NDC London 2013 - Mongo db for c# developers

  • 1. MongoDB for C# Developers Simon Elliston Ball Head of Big Data ! @sireb ! ! ! !
  • 4. Document Database id full_name address 1 John Smith 3a Test Street 2 Jane Doe 1b Fake Street 3 ... ...
  • 5. Document Database id full_name address 1 John Smith 3a Test Street 2 Jane Doe 1b Fake Street 3 ... ... 1 customer_i d 1 ... 2 1 ... order_date 2013-10-1 0 ... 3 ... ... ... id
  • 6. Document Database id full_name address 1 John Smith 3a Test Street 2 Jane Doe 1b Fake Street id 3 ...order_id 1 1 1 2 customer_i d3 1 2 1 ... 3 ... ... id ... product_id 1 ...... 103 order_date ... 2013-10-1 ... 0 ... ...
  • 7. Document Database id full_name address 1 John Smith 3a Test Street 2 Jane Doe 1b Fake Street id customer_id ... 1 3 1 1 2 customer_i d3 1 2 1 ... 3 ... ... id 1 ...... ... order_date 2013-10-10 order_date ... 2013-10-1 ... 0 ... ...
  • 8. Document Database id full_name address 1 John Smith 3a Test Street 2 Jane Doe 1b Fake Street id customer_id ... 1 3 1 1 2 customer_i d3 1 2 1 ... 3 ... ... id 1 ...... ... order_date 2013-10-10 order_date ... 2013-10-1 ... 0 ... ... customers = [ { "_id" : ObjectId("5256b399ac46b80084974d9a"), "name" : "John Smith", "address" : "3a Test Street", "orders" [ { "order_date": "2013-10-10", "order_item": [ { "product": "Widget"...} ... ] ... }] }, { "_id" : ObjectId("5256b3a8ac46b80084974d9b"), "name" : "Jane Doe", "address" : "1b Fake Street" } ]
  • 10. Document Database - Why? Flexible Data Model - No Schema Rapid Development Scalability
  • 11. Document Database - When? Blogs
  • 12. Document Database - When? Content management When read patterns are fixed Scaling requirements are unknown When write speed matters
  • 13.
  • 14.
  • 15.
  • 16. • Transactions per document • ACID, multi-document • Master-slave replication • But… Background Indexing • Many many languages: C#, • Master-master replication JavaScript, Java, PHP, Python, Ruby, • .NET Only Scala, Erlang, Go, C, C++, Perl (and those are just the official ones)
  • 17. • Main interface: CLI • GUI Client • Transactions per document • Native JSON • Master-slave replication • Geo-aware replication • Many many languages: C#, • REST Interface, so anything JavaScript, Java, PHP, Python, Ruby, • View based queries Scala, Erlang, Go, C, C++, Perl (and those are just the official ones)
  • 18. Getting started with MongoDB Download from http://www.mongodb.org/
  • 19.
  • 20. Getting started with the C# client PM> Install-Package mongocsharpdriver
  • 21.
  • 22. Wooah there. I thought you said JSON...
  • 26. BSON Binary JSON Typed Serialisation library Annotate POCOs to control mapping or write config code if you must
  • 27. Connecting... var connectionString = "mongodb://localhost"; var client = new MongoClient(connectionString); var server = client.GetServer();
  • 28. Connecting... var connectionString = "mongodb://localhost"; var client = new MongoClient(connectionString); var server = client.GetServer(); That’s it. The driver will disconnect, release objects and pool for you. ! But...
  • 30. CRUD creating new documents With mapped entities: var developerCollection = database.GetCollection<Developer>("team"); ! var Developer = new Developer(1,"Test", "Person"); developerCollection.Insert(Developer); var Developer2 = new Developer(2,"Another", "Developer"); developerCollection.Insert(Developer2) The BsonDocument way: var documentCollection = database.GetCollection("team"); ! BsonDocument document = new BsonDocument(); document.Add(new BsonElement("name", "Testing")) .Add(new BsonElement("number", new BsonInt32(42))); ! documentCollection.Insert(document);
  • 31. CRUD creating new documents The BsonDocument way: var documentCollection = database.GetCollection("team"); ! BsonDocument document = new BsonDocument(); document.Add(new BsonElement("name", "Testing")) .Add(new BsonElement("number", new BsonInt32(42))); ! documentCollection.Insert(document); Beware of mixing your BSONs List<Developer> allDevelopers = developerResults.ToList<Developer>();
  • 32. CRUD creating new documents Beware of mixing your BSONs List<Developer> allDevelopers = developerResults.ToList<Developer>();
  • 33. CRUD basic document reads MongoCursor<BsonDocument> documentResults = documentCollection.FindAll(); MongoCursor<Developer> developerResults = developerCollection.FindAll();
  • 34. CRUD basic document reads MongoCursor<BsonDocument> documentResults = documentCollection.FindAll(); MongoCursor<Developer> developerResults = developerCollection.FindAll(); var cursor = collection.FindAll(); cursor.Skip = 100; cursor.Limit = 10; ! foreach (var developer in cursor) { ...
  • 35. CRUD basic document reads MongoCursor<BsonDocument> documentResults = documentCollection.FindAll(); MongoCursor<Developer> developerResults = developerCollection.FindAll(); var cursor = collection.FindAll(); cursor.Skip = 100; cursor.Limit = 10; ! foreach (var developer in cursor) { ... } var readQuery = Query<Developer>.EQ(n => n.PersonId, 2); Developer developerRead = developerCollection.FindOne(readQuery);
  • 36. CRUD basic document reads MongoCursor<BsonDocument> documentResults = documentCollection.FindAll(); MongoCursor<Developer> developerResults = developerCollection.FindAll(); var cursor = collection.FindAll(); cursor.Skip = 100; cursor.Limit = 10; ! foreach (var developer in cursor) { ... } var readQuery = Query<Developer>.EQ(n => n.PersonId, 2); Developer developerRead = developerCollection.FindOne(readQuery); BsonDocument documentRead = documentCollection.FindOne(new QueryDocument { { "_id", documentId } });
  • 37. CRUD update developerRead.LastName = "Something-Else"; developerCollection.Save(developerRead);
  • 38. CRUD update Write Concerns Only relevant with Replication The number of replicas which need to report successful writes collection.Save(developerRead, new MongoInsertOptions { WriteConcern = WriteConcern.WMajority } );
  • 39. CRUD update var update = new UpdateDocument { { "$set", new BsonDocument("LastName", "A new name") } }; ! var query = new QueryDocument { { "LastName", "Developer" } }; ! collection.Update(query, update); NB. Only updates one document
  • 40. CRUD update var update = new UpdateDocument { { "$set", new BsonDocument("LastName", "A new name") } }; ! var query = new QueryDocument { { "LastName", "Developer" } }; ! collection.Update(query, update); NB. Only updates one document collection.Update(query, update, new MongoUpdateOptions { Flags = UpdateFlags.Multi }); Applies to all documents that match query
  • 41. CRUD upsert var update = new UpdateDocument { { "$set", new BsonDocument("LastName", "A new name") } }; var query = Query<Developer>.EQ(d => d.PersonId, 10); ! collection.Update(query, update, new MongoUpdateOptions { Flags = UpdateFlags.Upsert });
  • 42. CRUD deleting var query = new QueryDocument { { "LastName", "Person" } }; collection.Remove(query);
  • 43. CRUD deleting var query = new QueryDocument { { "LastName", "Person" } }; collection.Remove(query); collection.RemoveAll(); collection.Drop();
  • 44. LINQ integration Just make the collection queryable using System.Linq; using MongoDB.Driver.Linq; ! var query = from e in collection.AsQueryable() where e.LastName == "Person" select e; ! foreach (var developer in query){ ...
  • 45. GridFS in C# 16MB document limit GridFS used to break documents into chunks using (var fs = new FileStream("largeVideo.m4v", FileMode.Open)) { database.GridFS.Upload(fs, "largeVideo.m4v"); } database.GridFS.Download("test.m4v", "largeVideo.m4v");
  • 46. MapReduce (JavaScript) 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); Yes, it’s a word count. Yes, it’s JavaScript.
  • 47. Special Queries GeoNear var query = Query.EQ("properties.amenity", new BsonString("pub")); // here double lon = 54.9117468; double lat = -1.3737675; ! var earthRadius = 6378.0; // km var rangeInKm = 3000.0; // km ! var options = GeoNearOptions .SetMaxDistance(rangeInKm / earthRadius /* to radians */) .SetSpherical(true); ! var results = collection.GeoNear(query, lat, lon, 10, options); ! foreach (var result in results.Hits) ...
  • 51. Aggregation Framework Pipeline based Chained operators $project $match $limit $skip $unwind $group $sort … http://docs.mongodb.org/manual/reference/operator/aggregation/
  • 53. Summary Document databases are simple BSON annotation makes POCO mapping is easy CRUD is straight forward You can use LINQ Hard stuff is possible
  • 54. Acknowledgements MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
  • 55. Resources The MongoDB C Sharp Language Center: http://docs.mongodb.org/ecosystem/drivers/csharp/ A tutorial on the driver from MongoDB themselves: http://docs.mongodb.org/ecosystem/tutorial/use-csharp-driver/#csharp-driver-tutorial Sample code from this talk: https://github.com/simonellistonball/MongoForCsharpSamples A good walkthrough on MongoDB with ASP.NET MVC: http://www.drdobbs.com/database/mongodb-with-c-deep-dive/240152181 Bonus extras A Glimpse plugin to view mongo query details: https://github.com/simonellistonball/Glimpse.MongoDB