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)

An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React render props
React render propsReact render props
React render props
Saikat Samanta
 
React js
React jsReact js
React js
Oswald Campesato
 
Spring Boot 소개
Spring Boot 소개Spring Boot 소개
Spring Boot 소개
beom kyun choi
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
React state
React  stateReact  state
React state
Ducat
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
Hari kiran G
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
Rob Gietema
 
Dapper
DapperDapper
Dapper
Suresh Loganatha
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
React Context API
React Context APIReact Context API
React Context API
NodeXperts
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Kanushka Gayan
 
스프링 부트와 로깅
스프링 부트와 로깅스프링 부트와 로깅
스프링 부트와 로깅
Keesun Baik
 
Calender in asp.net
Calender in asp.netCalender in asp.net
Calender in asp.net
Sireesh K
 
Angular
AngularAngular
Angular
LearningTech
 
Spring boot
Spring bootSpring boot
Spring boot
Bhagwat Kumar
 
React native
React nativeReact native
React native
Mohammed El Rafie Tarabay
 
카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린
if kakao
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
Er. Kamal Bhusal
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기
영우 박
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
React state
React  stateReact  state
React state
Ducat
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
Hari kiran G
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
Rob Gietema
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
React Context API
React Context APIReact Context API
React Context API
NodeXperts
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Kanushka Gayan
 
스프링 부트와 로깅
스프링 부트와 로깅스프링 부트와 로깅
스프링 부트와 로깅
Keesun Baik
 
Calender in asp.net
Calender in asp.netCalender in asp.net
Calender in asp.net
Sireesh K
 
카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린
if kakao
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기
영우 박
 

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

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
MongoDB
 
Welcome the Offical C# Driver for MongoDB
Welcome the Offical C# Driver for MongoDBWelcome the Offical C# Driver for MongoDB
Welcome the Offical C# Driver for MongoDB
MongoDB
 
Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.
Rich Helton
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
Serdar Buyuktemiz
 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
Simon Elliston Ball
 
Getting Started with MongoDB Using the Microsoft Stack
Getting Started with MongoDB Using the Microsoft Stack Getting Started with MongoDB Using the Microsoft Stack
Getting Started with MongoDB Using the Microsoft Stack
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
MongoDB
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developers
Simon Elliston Ball
 
MongoDB
MongoDBMongoDB
MongoDB
Serdar Buyuktemiz
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
Introduction to MongoDB Basics from SQL to NoSQL
Introduction to MongoDB Basics from SQL to NoSQLIntroduction to MongoDB Basics from SQL to NoSQL
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
Norberto Leite
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
saikiran
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
Andreas Jung
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
Mongodb Introduction
Mongodb Introduction Mongodb Introduction
Mongodb Introduction
Nabeel Naqeebi
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
WebGeek Philippines
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
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
MongoDB
 
Welcome the Offical C# Driver for MongoDB
Welcome the Offical C# Driver for MongoDBWelcome the Offical C# Driver for MongoDB
Welcome the Offical C# Driver for MongoDB
MongoDB
 
Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.
Rich Helton
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
Serdar Buyuktemiz
 
Getting Started with MongoDB Using the Microsoft Stack
Getting Started with MongoDB Using the Microsoft Stack Getting Started with MongoDB Using the Microsoft Stack
Getting Started with MongoDB Using the Microsoft Stack
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
MongoDB
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developers
Simon Elliston Ball
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
Introduction to MongoDB Basics from SQL to NoSQL
Introduction to MongoDB Basics from SQL to NoSQLIntroduction to MongoDB Basics from SQL to NoSQL
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
saikiran
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
Andreas Jung
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
WebGeek Philippines
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Ad

More from Stefano Paluello (10)

Clinical Data and AI
Clinical Data and AIClinical Data and AI
Clinical Data and AI
Stefano Paluello
 
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
Stefano Paluello
 
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
Stefano Paluello
 
Grandata
GrandataGrandata
Grandata
Stefano Paluello
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
Stefano Paluello
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
Stefano Paluello
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
Stefano Paluello
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
Stefano Paluello
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologies
Stefano Paluello
 
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
Stefano Paluello
 
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
Stefano Paluello
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
Stefano Paluello
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologies
Stefano Paluello
 
Ad

Recently uploaded (20)

Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdfHigh Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdfHigh Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptxFIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 

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.