SlideShare une entreprise Scribd logo
1  sur  24
+ Using MongoDB on Windows with the .Net Framework and C#
Let me introduce myself… Stefano Paluello All around geek   @ Barcrest Group & Pastesoft stefano.paluello@gmail.com stefanopaluello.wordpress.com Twitter: @palutz http://www.pastesoft.com
What is MongoDB? It’s an open source document oriented database: Full index support Replication & High Availability Scalable (auto-sharding) High performance (written in C++, atomic update,…) Rich query support Map/Reduce GridFS (store files without problem) Commercial support
Setting up MongoDB on Windows Download your version (better the 64bit Production release) from the official website: http://www.mongodb.org/downloads
Running MongoDB server… Best place where to look at (Windows quickstart): http://www.mongodb.org/display/DOCS/Quickstart+Windows Unzip, create log and data dir, run it 
Ok. Are we running? Let’s connect to the shell and check it $mongodirinongo.exe
MongoDB can run as service Official guide: http://www.mongodb.org/display/DOCS/Windows+Service Easy way:  $mongodirinongod  –install Let’s add some “flavour”: $mongodirinongod --logpath .ogogs --logappend --dbpath .ata –directoryperdb –install To manage it, NET START mongos, NET STOP mongos
MongoDB C#/.Net driver Official, high performance, fully featured C# driver supported by 10gen Now at version 1.2 Built and tested against MongoDB 1.8.3 e 2.0.0 on : Visual Studio 2008, Visual Studio 2010 MonoDevelop 2.6 (Mono 2.10) It can be downloaded from github.com: 	http://github.com/mongodb/mongo-csharp-driver NuGet: PM> Install-Package mongocsharpdriver http://www.nuget.org/List/Packages/mongocsharpdriver
MongoDB C#/.Net driver on NuGet
MongoDB C#/.Net driver Two main (separated) assemblies: MongoDB.Bson.dll MongoDB.Driver.dll (you can use other drivers) Namespaces (required) MongoDB.Bson; MongoDB.Driver; Namespace (additional)  MongoDB.Bson.IO, MongoDB.Bson.Serialization; MongoDB.Bson.Serialization.*, MongoDB.Driver.GridFs
BSON Namespace Represent the BSON Object Model A set of classes that handle all the specification of BSON documents (I/O, serialization, in-memory object model) Main classes: BsonDocument BsonElement BsonValue (abstract class), with BsonTypeenum property BsonArray BsonDateTime BsonDocument BsonInt32 BsonObjectId BsonString
BSON Object Model BsonDocument is the main class BsonDocument is a collection of elements (BsonElements ) BsonElement is a name/value pair where the value is a BsonValue (with its own BsonType) The BsonElement class is seldom used directly cause it’s created as needed implicitly: document.Add(new BsonElement(“Name”, “Stefano”)); document.Add(“Name”, “Stefano”));
MongoDB.Driver Main classes (all thread-safe): MongoServer MongoDatabase MongoCollection<TDocument> MongoCursor<Tdocument> (only when frozen) MongoServersrv = MongoServer.Create(); Every URL has a MongoServer instance (different Create calls with the same URL return with the same MongoServer instance NOT put in the session state (NOT serializable)
MongoDB.Driver MongoServersrv = MongoServer.Create(); Every URL has a MongoServer instance  different Create() calls with the same URL return with the same MongoServerinstance Do NOT put in the session state (NOT serializable) The driver manage a Connection Pools (one Connection Pools for every server) The connections are shared with all threads
MongoDB Driver MongoCollection : The class manages a collection of BsonDocument in a MongoDB database MongoCollection<TDefaultDocument>: Manage a collection of document, with the default type specified by the TDefaultDocument parameter GetCollection
MongoCollection class CRUD with Mongo – Query a collection FindOne and FindOneAs<T> IMongoQuery objects (QueryComplete) Find(query)
MongoCollection class CRUD with MongoDB - Insert There are many ways to insert data into a MongoDB collection (using the BsonDocument or any object that can be serialized
MongoCollection class CRUD with MongoDB – Update and Save There are many ways to update a document
MongoCollection class CRUD with MongoDB – Delete There are many ways to delete a Document
Let’s play a bit with the code…
Useful (IMHO) tools
MongoVue (www.mongovue.com)
Chrome Webstore – Mongo Live
Another code demo Get dynamics with C#

Contenu connexe

Tendances

Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015
Holden Karau
 

Tendances (20)

MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
 
Express js
Express jsExpress js
Express js
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Data Modeling for MongoDB
Data Modeling for MongoDBData Modeling for MongoDB
Data Modeling for MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Code Refactoring Cheatsheet
Code Refactoring CheatsheetCode Refactoring Cheatsheet
Code Refactoring Cheatsheet
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Firebase
FirebaseFirebase
Firebase
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Web api
Web apiWeb api
Web api
 

Similaire à Using MongoDB with the .Net Framework

From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)
MongoSF
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
MongoSF
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
chriskite
 

Similaire à Using MongoDB with the .Net Framework (20)

MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & Execution
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.
 
Migrating from MySQL to MongoDB at Wordnik
Migrating from MySQL to MongoDB at WordnikMigrating from MySQL to MongoDB at Wordnik
Migrating from MySQL to MongoDB at Wordnik
 
From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)
 
MongoDB on Windows Azure
MongoDB on Windows AzureMongoDB on Windows Azure
MongoDB on Windows Azure
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)Introduction to MongoDB (Webinar Jan 2011)
Introduction to MongoDB (Webinar Jan 2011)
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10genIntroduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10gen
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
 

Plus de Stefano Paluello (10)

Clinical Data and AI
Clinical Data and AIClinical Data and AI
Clinical Data and AI
 
Real scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the CloudReal scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the Cloud
 
A gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and HadoopA gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and Hadoop
 
Grandata
GrandataGrandata
Grandata
 
How to use asana
How to use asanaHow to use asana
How to use asana
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologies
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Using MongoDB with the .Net Framework

  • 1. + Using MongoDB on Windows with the .Net Framework and C#
  • 2. Let me introduce myself… Stefano Paluello All around geek  @ Barcrest Group & Pastesoft stefano.paluello@gmail.com stefanopaluello.wordpress.com Twitter: @palutz http://www.pastesoft.com
  • 3. What is MongoDB? It’s an open source document oriented database: Full index support Replication & High Availability Scalable (auto-sharding) High performance (written in C++, atomic update,…) Rich query support Map/Reduce GridFS (store files without problem) Commercial support
  • 4. Setting up MongoDB on Windows Download your version (better the 64bit Production release) from the official website: http://www.mongodb.org/downloads
  • 5. Running MongoDB server… Best place where to look at (Windows quickstart): http://www.mongodb.org/display/DOCS/Quickstart+Windows Unzip, create log and data dir, run it 
  • 6. Ok. Are we running? Let’s connect to the shell and check it $mongodirinongo.exe
  • 7. MongoDB can run as service Official guide: http://www.mongodb.org/display/DOCS/Windows+Service Easy way: $mongodirinongod –install Let’s add some “flavour”: $mongodirinongod --logpath .ogogs --logappend --dbpath .ata –directoryperdb –install To manage it, NET START mongos, NET STOP mongos
  • 8. MongoDB C#/.Net driver Official, high performance, fully featured C# driver supported by 10gen Now at version 1.2 Built and tested against MongoDB 1.8.3 e 2.0.0 on : Visual Studio 2008, Visual Studio 2010 MonoDevelop 2.6 (Mono 2.10) It can be downloaded from github.com: http://github.com/mongodb/mongo-csharp-driver NuGet: PM> Install-Package mongocsharpdriver http://www.nuget.org/List/Packages/mongocsharpdriver
  • 10. MongoDB C#/.Net driver Two main (separated) assemblies: MongoDB.Bson.dll MongoDB.Driver.dll (you can use other drivers) Namespaces (required) MongoDB.Bson; MongoDB.Driver; Namespace (additional) MongoDB.Bson.IO, MongoDB.Bson.Serialization; MongoDB.Bson.Serialization.*, MongoDB.Driver.GridFs
  • 11. BSON Namespace Represent the BSON Object Model A set of classes that handle all the specification of BSON documents (I/O, serialization, in-memory object model) Main classes: BsonDocument BsonElement BsonValue (abstract class), with BsonTypeenum property BsonArray BsonDateTime BsonDocument BsonInt32 BsonObjectId BsonString
  • 12. BSON Object Model BsonDocument is the main class BsonDocument is a collection of elements (BsonElements ) BsonElement is a name/value pair where the value is a BsonValue (with its own BsonType) The BsonElement class is seldom used directly cause it’s created as needed implicitly: document.Add(new BsonElement(“Name”, “Stefano”)); document.Add(“Name”, “Stefano”));
  • 13. MongoDB.Driver Main classes (all thread-safe): MongoServer MongoDatabase MongoCollection<TDocument> MongoCursor<Tdocument> (only when frozen) MongoServersrv = MongoServer.Create(); Every URL has a MongoServer instance (different Create calls with the same URL return with the same MongoServer instance NOT put in the session state (NOT serializable)
  • 14. MongoDB.Driver MongoServersrv = MongoServer.Create(); Every URL has a MongoServer instance different Create() calls with the same URL return with the same MongoServerinstance Do NOT put in the session state (NOT serializable) The driver manage a Connection Pools (one Connection Pools for every server) The connections are shared with all threads
  • 15. MongoDB Driver MongoCollection : The class manages a collection of BsonDocument in a MongoDB database MongoCollection<TDefaultDocument>: Manage a collection of document, with the default type specified by the TDefaultDocument parameter GetCollection
  • 16. MongoCollection class CRUD with Mongo – Query a collection FindOne and FindOneAs<T> IMongoQuery objects (QueryComplete) Find(query)
  • 17. MongoCollection class CRUD with MongoDB - Insert There are many ways to insert data into a MongoDB collection (using the BsonDocument or any object that can be serialized
  • 18. MongoCollection class CRUD with MongoDB – Update and Save There are many ways to update a document
  • 19. MongoCollection class CRUD with MongoDB – Delete There are many ways to delete a Document
  • 20. Let’s play a bit with the code…
  • 23. Chrome Webstore – Mongo Live
  • 24. Another code demo Get dynamics with C#

Notes de l'éditeur

  1. Full index:Index on any attribute, just like you&apos;re used to.
  2. Full index:Index on any attribute, just like you&apos;re used to.
  3. Full index:Index on any attribute, just like you&apos;re used to.
  4. Full index:Index on any attribute, just like you&apos;re used to.
  5. Full index:Index on any attribute, just like you&apos;re used to.
  6. Full index:Index on any attribute, just like you&apos;re used to.
  7. Full index:Index on any attribute, just like you&apos;re used to.
  8. Full index:Index on any attribute, just like you&apos;re used to.
  9. Full index:Index on any attribute, just like you&apos;re used to.
  10. Full index:Index on any attribute, just like you&apos;re used to.
  11. Full index:Index on any attribute, just like you&apos;re used to.
  12. Full index:Index on any attribute, just like you&apos;re used to.
  13. Full index:Index on any attribute, just like you&apos;re used to.
  14. Full index:Index on any attribute, just like you&apos;re used to.
  15. Full index:Index on any attribute, just like you&apos;re used to.
  16. Full index:Index on any attribute, just like you&apos;re used to.
  17. Full index:Index on any attribute, just like you&apos;re used to.
  18. Full index:Index on any attribute, just like you&apos;re used to.
  19. Full index:Index on any attribute, just like you&apos;re used to.
  20. Full index:Index on any attribute, just like you&apos;re used to.
  21. Full index:Index on any attribute, just like you&apos;re used to.