SlideShare a Scribd company logo
+Using MongoDB on Windows with the .Net Framework and C#
Let me introduce myself…Stefano PaluelloAll around geek   @ Barcrest Group & Pastesoftstefano.paluello@gmail.comstefanopaluello.wordpress.comTwitter: @palutzhttp://www.pastesoft.com
What is MongoDB?It’s an open source document oriented database:Full index supportReplication & High AvailabilityScalable (auto-sharding)High performance (written in C++, atomic update,…)Rich query supportMap/ReduceGridFS (store files without problem)Commercial support
Setting up MongoDB on WindowsDownload 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+WindowsUnzip, create log and data dir, run it 
Ok. Are we running?Let’s connect to the shell and check it$mongodir\bin\mongo.exe
MongoDB can run as serviceOfficial guide:http://www.mongodb.org/display/DOCS/Windows+ServiceEasy way: $mongodir\bin\mongod  –installLet’s add some “flavour”:$mongodir\bin\mongod --logpath .\log\logs --logappend --dbpath .\data –directoryperdb –installTo manage it, NET START mongos, NET STOP mongos
MongoDB C#/.Net driverOfficial, high performance, fully featured C# driver supported by 10genNow at version 1.2Built and tested against MongoDB 1.8.3 e 2.0.0 on :Visual Studio 2008, Visual Studio 2010MonoDevelop 2.6 (Mono 2.10)It can be downloaded from github.com: 	http://github.com/mongodb/mongo-csharp-driverNuGet:PM> Install-Package mongocsharpdriverhttp://www.nuget.org/List/Packages/mongocsharpdriver
MongoDB C#/.Net driver on NuGet
MongoDB C#/.Net driverTwo main (separated) assemblies:MongoDB.Bson.dllMongoDB.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 NamespaceRepresent the BSON Object ModelA set of classes that handle all the specification of BSON documents (I/O, serialization, in-memory object model)Main classes:BsonDocumentBsonElementBsonValue (abstract class), with BsonTypeenum propertyBsonArrayBsonDateTimeBsonDocumentBsonInt32BsonObjectIdBsonString
BSON Object ModelBsonDocument is the main classBsonDocument 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.DriverMain classes (all thread-safe):MongoServerMongoDatabaseMongoCollection<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 instanceNOT put in the session state (NOT serializable)
MongoDB.DriverMongoServersrv = MongoServer.Create();Every URL has a MongoServer instance different Create() calls with the same URL return with the same MongoServerinstanceDo 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 DriverMongoCollection :The class manages a collection of BsonDocument in a MongoDB databaseMongoCollection<TDefaultDocument>:Manage a collection of document, with the default type specified by the TDefaultDocument parameterGetCollection
MongoCollection classCRUD with Mongo – Query a collectionFindOne and FindOneAs<T>IMongoQuery objects (QueryComplete)Find(query)
MongoCollection classCRUD with MongoDB - InsertThere are many ways to insert data into a MongoDB collection (using the BsonDocument or any object that can be serialized
MongoCollection classCRUD with MongoDB – Update and SaveThere are many ways to update a document
MongoCollection classCRUD with MongoDB – DeleteThere 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 demoGet dynamics with C#

More Related Content

What's hot (20)

PDF
Introduction to TensorFlow
Matthias Feys
 
PDF
Deep Reinforcement learning
Cairo University
 
PPT
.Net Overview -- Training (Lesson 1)
Rishi Kothari
 
PPTX
Jetpack Compose - Android’s modern toolkit for building native UI
Gilang Ramadhan
 
PDF
Android Networking
Maksym Davydov
 
PDF
Convolutional Neural Network Models - Deep Learning
Mohamed Loey
 
PPTX
Convolutional Neural Network
Vignesh Suresh
 
PPTX
Android User Interface
Shakib Hasan Sumon
 
PPTX
Java Spring Framework
Mehul Jariwala
 
PDF
Chapter6 database connectivity
KV(AFS) Utarlai, Barmer (Rajasthan)
 
PPTX
React Native
ASIMYILDIZ
 
PPTX
Graph Attention Networks.pptx
ssuser2624f71
 
PPTX
AlexNet
Bertil Hatt
 
PPTX
Spring JDBCTemplate
Guo Albert
 
PPTX
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
PPTX
Android+init+process
Hong Jae Kwon
 
PPT
Java database connectivity
Vaishali Modi
 
PDF
Video Classification Basic
Silversparro Technologies
 
PPTX
CNN Tutorial
Sungjoon Choi
 
PPTX
Basic android-ppt
Srijib Roy
 
Introduction to TensorFlow
Matthias Feys
 
Deep Reinforcement learning
Cairo University
 
.Net Overview -- Training (Lesson 1)
Rishi Kothari
 
Jetpack Compose - Android’s modern toolkit for building native UI
Gilang Ramadhan
 
Android Networking
Maksym Davydov
 
Convolutional Neural Network Models - Deep Learning
Mohamed Loey
 
Convolutional Neural Network
Vignesh Suresh
 
Android User Interface
Shakib Hasan Sumon
 
Java Spring Framework
Mehul Jariwala
 
Chapter6 database connectivity
KV(AFS) Utarlai, Barmer (Rajasthan)
 
React Native
ASIMYILDIZ
 
Graph Attention Networks.pptx
ssuser2624f71
 
AlexNet
Bertil Hatt
 
Spring JDBCTemplate
Guo Albert
 
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
Android+init+process
Hong Jae Kwon
 
Java database connectivity
Vaishali Modi
 
Video Classification Basic
Silversparro Technologies
 
CNN Tutorial
Sungjoon Choi
 
Basic android-ppt
Srijib Roy
 

Similar to Using MongoDB with the .Net Framework (20)

PPTX
MongoDB Introduction, Installation & Execution
iFour Technolab Pvt. Ltd.
 
ODP
Introduction to MongoDB with PHP
fwso
 
ODP
Mongo db rev001.
Rich Helton
 
PPTX
Migrating from MySQL to MongoDB at Wordnik
Tony Tam
 
PPTX
From MySQL to MongoDB at Wordnik (Tony Tam)
MongoSF
 
PPTX
MongoDB on Windows Azure
MongoDB
 
PDF
Mongo learning series
Prashanth Panduranga
 
PDF
Quick & Dirty & MEAN
Troy Miles
 
PPT
Java Development with MongoDB (James Williams)
MongoSF
 
PDF
MongoDB - An Introduction
sethfloydjr
 
PDF
MongoDB and Node.js
Norberto Leite
 
PPT
Introduction to MongoDB (Webinar Jan 2011)
MongoDB
 
PDF
Java Persistence Frameworks for MongoDB
MongoDB
 
PPTX
Introduction to the new official C# Driver developed by 10gen
MongoDB
 
PPTX
Intro To Mongo Db
chriskite
 
PPTX
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
PDF
How do i Meet MongoDB
Antonio Scalzo
 
PPTX
Basics of MongoDB
HabileLabs
 
PPTX
Introduction to MongoDB
Chun-Kai Wang
 
PPTX
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
Maarten Balliauw
 
MongoDB Introduction, Installation & Execution
iFour Technolab Pvt. Ltd.
 
Introduction to MongoDB with PHP
fwso
 
Mongo db rev001.
Rich Helton
 
Migrating from MySQL to MongoDB at Wordnik
Tony Tam
 
From MySQL to MongoDB at Wordnik (Tony Tam)
MongoSF
 
MongoDB on Windows Azure
MongoDB
 
Mongo learning series
Prashanth Panduranga
 
Quick & Dirty & MEAN
Troy Miles
 
Java Development with MongoDB (James Williams)
MongoSF
 
MongoDB - An Introduction
sethfloydjr
 
MongoDB and Node.js
Norberto Leite
 
Introduction to MongoDB (Webinar Jan 2011)
MongoDB
 
Java Persistence Frameworks for MongoDB
MongoDB
 
Introduction to the new official C# Driver developed by 10gen
MongoDB
 
Intro To Mongo Db
chriskite
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
How do i Meet MongoDB
Antonio Scalzo
 
Basics of MongoDB
HabileLabs
 
Introduction to MongoDB
Chun-Kai Wang
 
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
Maarten Balliauw
 
Ad

More from Stefano Paluello (10)

PPTX
Clinical Data and AI
Stefano Paluello
 
PPTX
Real scenario: moving a legacy app to the Cloud
Stefano Paluello
 
PPTX
A gentle introduction to the world of BigData and Hadoop
Stefano Paluello
 
PPTX
Grandata
Stefano Paluello
 
PDF
How to use asana
Stefano Paluello
 
PDF
Windows Azure Overview
Stefano Paluello
 
PPTX
TDD with Visual Studio 2010
Stefano Paluello
 
PPTX
Asp.Net MVC Intro
Stefano Paluello
 
PPTX
Entity Framework 4
Stefano Paluello
 
PPTX
Teamwork and agile methodologies
Stefano Paluello
 
Clinical Data and AI
Stefano Paluello
 
Real scenario: moving a legacy app to the Cloud
Stefano Paluello
 
A gentle introduction to the world of BigData and Hadoop
Stefano Paluello
 
How to use asana
Stefano Paluello
 
Windows Azure Overview
Stefano Paluello
 
TDD with Visual Studio 2010
Stefano Paluello
 
Asp.Net MVC Intro
Stefano Paluello
 
Entity Framework 4
Stefano Paluello
 
Teamwork and agile methodologies
Stefano Paluello
 
Ad

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 

Using MongoDB with the .Net Framework

  • 1. +Using MongoDB on Windows with the .Net Framework and C#
  • 2. Let me introduce myself…Stefano PaluelloAll around geek  @ Barcrest Group & Pastesoftstefano.paluello@gmail.comstefanopaluello.wordpress.comTwitter: @palutzhttp://www.pastesoft.com
  • 3. What is MongoDB?It’s an open source document oriented database:Full index supportReplication & High AvailabilityScalable (auto-sharding)High performance (written in C++, atomic update,…)Rich query supportMap/ReduceGridFS (store files without problem)Commercial support
  • 4. Setting up MongoDB on WindowsDownload 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+WindowsUnzip, create log and data dir, run it 
  • 6. Ok. Are we running?Let’s connect to the shell and check it$mongodir\bin\mongo.exe
  • 7. MongoDB can run as serviceOfficial guide:http://www.mongodb.org/display/DOCS/Windows+ServiceEasy way: $mongodir\bin\mongod –installLet’s add some “flavour”:$mongodir\bin\mongod --logpath .\log\logs --logappend --dbpath .\data –directoryperdb –installTo manage it, NET START mongos, NET STOP mongos
  • 8. MongoDB C#/.Net driverOfficial, high performance, fully featured C# driver supported by 10genNow at version 1.2Built and tested against MongoDB 1.8.3 e 2.0.0 on :Visual Studio 2008, Visual Studio 2010MonoDevelop 2.6 (Mono 2.10)It can be downloaded from github.com: http://github.com/mongodb/mongo-csharp-driverNuGet:PM> Install-Package mongocsharpdriverhttp://www.nuget.org/List/Packages/mongocsharpdriver
  • 10. MongoDB C#/.Net driverTwo main (separated) assemblies:MongoDB.Bson.dllMongoDB.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 NamespaceRepresent the BSON Object ModelA set of classes that handle all the specification of BSON documents (I/O, serialization, in-memory object model)Main classes:BsonDocumentBsonElementBsonValue (abstract class), with BsonTypeenum propertyBsonArrayBsonDateTimeBsonDocumentBsonInt32BsonObjectIdBsonString
  • 12. BSON Object ModelBsonDocument is the main classBsonDocument 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.DriverMain classes (all thread-safe):MongoServerMongoDatabaseMongoCollection<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 instanceNOT put in the session state (NOT serializable)
  • 14. MongoDB.DriverMongoServersrv = MongoServer.Create();Every URL has a MongoServer instance different Create() calls with the same URL return with the same MongoServerinstanceDo 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 DriverMongoCollection :The class manages a collection of BsonDocument in a MongoDB databaseMongoCollection<TDefaultDocument>:Manage a collection of document, with the default type specified by the TDefaultDocument parameterGetCollection
  • 16. MongoCollection classCRUD with Mongo – Query a collectionFindOne and FindOneAs<T>IMongoQuery objects (QueryComplete)Find(query)
  • 17. MongoCollection classCRUD with MongoDB - InsertThere are many ways to insert data into a MongoDB collection (using the BsonDocument or any object that can be serialized
  • 18. MongoCollection classCRUD with MongoDB – Update and SaveThere are many ways to update a document
  • 19. MongoCollection classCRUD with MongoDB – DeleteThere are many ways to delete a Document
  • 20. Let’s play a bit with the code…
  • 23. Chrome Webstore – Mongo Live
  • 24. Another code demoGet dynamics with C#

Editor's Notes

  • #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.
  • #22: Full index:Index on any attribute, just like you&apos;re used to.
  • #23: Full index:Index on any attribute, just like you&apos;re used to.
  • #24: Full index:Index on any attribute, just like you&apos;re used to.
  • #25: Full index:Index on any attribute, just like you&apos;re used to.