SlideShare a Scribd company logo
MongoDB in C#
By Rich Helton
January 01, 2015
Buy “Mastering NserviceBus with
Persistence”
What is MongoDB
MongoDB is a cross-platform document-
oriented database.
http://en.wikipedia.org/wiki/MongoDB
➢
This means that it is NoSQL, not utilizing the
relational SQL commands, but utilizing JSON-
like documents to query the database.
➢
The JSON-like documents are BSON, Binary
JSON.
➢
MongoDB is free and open source.
➢
http://www.mongodb.org
What is MongoDB
➢
MongoDB is a cross-platform document-
oriented database.
http://en.wikipedia.org/wiki/MongoDB
➢
This means that it is NoSQL, not utilizing the
relational SQL commands, but utilizing JSON-like
documents to query the database.
➢
MongoDB is free and open source.
http://www.mongodb.org
The Motivation
●
Sometimes using a full Microsoft SQL
Server installation, with maintenance for
databases, may be a little overkill for
something as simple as keeping track of a
file history table.
●
The need for access control is still needed
for basic security, so something more than a
File I/O is required.
Installation
●
Installation instructions can be found to install
the correct version by checking the OS from
http://docs.mongodb.org/manual/tutorial/insta
ll-mongodb-on-windows/
●
The download page of the installations for
Windows, OSX, Solaris and Linux can be found
at http://www.mongodb.org/downloads
●
We can optionally move the downloaded files to
“C:mongodb”.
Installation MSI's
●
Alternately, you can just use the MongoDB MSI
file to install the program into the “C:Program
FilesMongoDB” directory.
●
For Win32,
http://dl.mongodb.org/dl/win32/i386
●
For Win64,
http://dl.mongodb.org/dl/win32/x86_64
Startup
●
An data directory needs to be created to store
the database, for example “md datadb”,
which “datadb” is the default directory for
mongod.
●
Running “C:mongodbbinmongod.exe” will
now create the database.
●
The “--auth” argument can be used to force
authentication into the server.
Running mongod.exe
There are many tools for MongoDB
➢
There are many admin tools, some can be
found at
http://docs.mongodb.org/ecosystem/tools/adm
➢
One of the admin tools that supports
multiple platforms and runs in Java is
Umongo, found at
http://edgytech.com/umongo/
Viewing the new database in
UMongo
After downloading Umongo, we run the
applications with the default settings to see
the new database:
Running as a Service
l
To run MongoDB as a service, we need a
config file and we will use the -install option
on this config file.
l
We will create a log directory in the
“C:datadb” directory.
Creating and starting the service
Running “mongod
--logpath=C:datadblogmongo.log
--install” as administrator in the command
prompt:
Viewing the service
After installing the service, we can see the
service running:
A recap of some of the exe's:
● mongo.exe – runs the database shell.
● mongod.exe – the core database.
● mongos.exe – auto sharding process.
● mongodump.exe – dump/export utility.
● mongorestore.exe – restore/import utility.
Start the C#
We will create a Command
program MongoDBConsoleApp1
NuGet the mongocsharpdriver
https://www.nuget.org/packages/mongocsha
rpdriver/
No matter the database, there
needs to be a connectionstring
l
Add an App.config with the “<add
key="connectionString"
value="Server=localhost:27017"/>”. The
default port for MongoDB is port 27017.
Starting the DB connection
l
We will get the connectionstring, and
connect to the database.
BSON and the DB
In order to perform CRUD operations on the
database, a BsonCollection is used to map to
the table. The table is really a collection of
documents. The documents being
name/value pairs.
Here, we have an insert of a document.
More on BSON

BSON is Binary JSON.

It is a name-value pair, in which the value
could be many different data types.

More on BSON can be found at
http://en.wikipedia.org/wiki/BSON
After the insert, verify

After the insert, we can verify the data in
UMongo.

Here, we see that a document was created
in the FileHistory collection.

We can also export the data to a text file.
Viewing the exported file
Code to read the collection

A table is just a collection of documents.
Each document has a name/value pair.

We walk through the collection reading the
name-value pair.
Updating the collection
➢
To update the collection, find the value in
the collection, change it, and save it in the
collection.
Deleting a document
➢
To remove a document, a query has to be
developed that matches a name-value pair.
Deleting a collection (table)
➢
To remove a collection, a drop need only be
performed on the collection.
static void Main(string[] args)
{
// get the App.config Connection String
string connString = ConfigurationManager.AppSettings["connectionString"];
// Get the client connection
var client = new MongoClient(connString);
// Get the MongoServer Object
var server = client.GetServer();
// Gets a link to the DB, will create with first insert
MongoDatabase myDatabase = server.GetDatabase("FileHistory");
// Create a BsonDocument list for the Table
MongoCollection<BsonDocument> filesReceivedTable =
myDatabase.GetCollection<BsonDocument>("BankFilesReceieved");
// Create an individual Table row with the fields
BsonDocument filesReceived = new BsonDocument {
{ "DateReceived", DateTime.Now },
{ "FileName", "BankFile1.txt" }};
// Insert into table
filesReceivedTable.Insert(filesReceived);
// Get the table collection
MongoCollection<BsonDocument> updateTable =
myDatabase.GetCollection<BsonDocument>("BankFilesReceieved");
// Walk through each document updating the name-value pair.
foreach (var filesRead in updateTable.FindAll())
{
foreach (var elements in filesRead.Elements)
{
if (elements.Name == "FileName")
{
elements.Value = "BankNameChanged.txt";
updateTable.Save(filesRead);
}
}
}
// Get the table collection
MongoCollection<BsonDocument> deletingRows =
myDatabase.GetCollection<BsonDocument>("BankFilesReceieved");
// Remove on query where a name = a specific value
deletingRows.Remove(Query.EQ("FileName","BankNameChanged.txt"));
// Get the table collection
MongoCollection<BsonDocument> readingTable =
myDatabase.GetCollection<BsonDocument>("BankFilesReceieved");
// Walk through each document reading the name-value pair.
foreach (var filesRead in readingTable.FindAll())
{
foreach (var elements in filesRead.Elements)
{
Console.WriteLine("Name :" + elements.Name);
Console.WriteLine("Value :" + elements.Value);
}
}
// Get the table collection
MongoCollection<BsonDocument> deletingTable =
myDatabase.GetCollection<BsonDocument>("BankFilesReceieved");
// Delecting the table
deletingTable.Drop();
}
Mongo Shell
Mongo Shell
● The mongo.exe is used to execute shell commands.
http://docs.mongodb.org/manual/reference/mongo-shell/
● The shell commands can be used to show databases, users,
collections, and also create the same.
Adding a user
● Can be created using the
“db.addUser(“user”,”password”) in the
mongo shell.
In C#, adding a user would be
similar to:
In C#, executing the function
could be done as:
In C#, finding all users would be
similar to:
In C#, finding all users would be
similar to:
User Roles
● Just because a user is added, doesn't mean
that the user has assigned roles.
● We can see the roles to be added in the
NoSQL Manager for MongoDB.
Mongo C# Driver
The Mongo C# driver
● The documentation can be found at
http://docs.mongodb.org/ecosystem/drivers/cs
● This was the nuget driver that we installed
earlier as version 1.9.2.
There are c-sharp community projects found
at
http://docs.mongodb.org/ecosystem/drivers/csh
, one of which is MongoCola.
MongoCola
● MongoCola is an c# open source Mongo Admin tool.
● The c-sharp source code for MongoCola can be found at
https://github.com/magicdict/MagicMongoDBTool
Some Admin Tools
Homepages
● MongoCola Homepage
http://osdig.com/project/index/id/22703.html#.VK
● No-SQL Manager for MongoDB
http://www.mongodbmanager.com/

More Related Content

What's hot

Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
Sunil kumar Mohanty
 
.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7
aminmesbahi
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Building web applications with Java & Spring
Building web applications with Java & SpringBuilding web applications with Java & Spring
Building web applications with Java & Spring
David Kiss
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
Oleg Tsal-Tsalko
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
Randy Connolly
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
kamal kotecha
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
aminmesbahi
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
Commit University
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
Nuha Noor
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
.NET Core, ASP.NET Core Course, Session 18
 .NET Core, ASP.NET Core Course, Session 18 .NET Core, ASP.NET Core Course, Session 18
.NET Core, ASP.NET Core Course, Session 18
aminmesbahi
 
Spring WebApplication development
Spring WebApplication developmentSpring WebApplication development
Spring WebApplication development
ThirupathiReddy Vajjala
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
Majurageerthan Arumugathasan
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11
aminmesbahi
 

What's hot (20)

Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
 
.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Building web applications with Java & Spring
Building web applications with Java & SpringBuilding web applications with Java & Spring
Building web applications with Java & Spring
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
.NET Core, ASP.NET Core Course, Session 18
 .NET Core, ASP.NET Core Course, Session 18 .NET Core, ASP.NET Core Course, Session 18
.NET Core, ASP.NET Core Course, Session 18
 
Spring WebApplication development
Spring WebApplication developmentSpring WebApplication development
Spring WebApplication development
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11
 

Similar to Mongo db rev001.

Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net Framework
Stefano Paluello
 
Local Storage
Local StorageLocal Storage
Local Storage
Ivano Malavolta
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
tarungupta276841
 
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
buildacloud
 
Open writing-cloud-collab
Open writing-cloud-collabOpen writing-cloud-collab
Open writing-cloud-collab
Karen Vuong
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
Experiment no 1
Experiment no 1Experiment no 1
Experiment no 1
Ankit Dubey
 
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
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdf
Inexture Solutions
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
fwso
 
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
Wildan Maulana
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
Prashanth Panduranga
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
Neeraj Mathur
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
Antonio Scalzo
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connector
kumar gaurav
 
Sqllite
SqlliteSqllite
Sqllite
Senthil Kumar
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
sethfloydjr
 
Endnote windows basic.2017
Endnote windows basic.2017Endnote windows basic.2017
Endnote windows basic.2017
Awot Kiflu Gebregziabher
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
Rob Dunn
 
The emerging world of mongo db csp
The emerging world of mongo db   cspThe emerging world of mongo db   csp
The emerging world of mongo db csp
Carlos Sánchez Pérez
 

Similar to Mongo db rev001. (20)

Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net Framework
 
Local Storage
Local StorageLocal Storage
Local Storage
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
 
Open writing-cloud-collab
Open writing-cloud-collabOpen writing-cloud-collab
Open writing-cloud-collab
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
Experiment no 1
Experiment no 1Experiment no 1
Experiment no 1
 
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
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdf
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
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
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connector
 
Sqllite
SqlliteSqllite
Sqllite
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Endnote windows basic.2017
Endnote windows basic.2017Endnote windows basic.2017
Endnote windows basic.2017
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
The emerging world of mongo db csp
The emerging world of mongo db   cspThe emerging world of mongo db   csp
The emerging world of mongo db csp
 

More from Rich Helton

Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
Rich Helton
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02
Rich Helton
 
NServicebus WCF Integration 101
NServicebus WCF Integration 101NServicebus WCF Integration 101
NServicebus WCF Integration 101
Rich Helton
 
Azure rev002
Azure rev002Azure rev002
Azure rev002
Rich Helton
 
Salesforce Intro
Salesforce IntroSalesforce Intro
Salesforce Intro
Rich Helton
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
Rich Helton
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad Programming
Rich Helton
 
First Steps in Android
First Steps in AndroidFirst Steps in Android
First Steps in Android
Rich Helton
 
NServiceBus
NServiceBusNServiceBus
NServiceBus
Rich Helton
 
Python For Droid
Python For DroidPython For Droid
Python For Droid
Rich Helton
 
Spring Roo Rev005
Spring Roo Rev005Spring Roo Rev005
Spring Roo Rev005
Rich Helton
 
Python Final
Python FinalPython Final
Python Final
Rich Helton
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
Rich Helton
 
Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
Rich Helton
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 Final
Rich Helton
 
Jira Rev002
Jira Rev002Jira Rev002
Jira Rev002
Rich Helton
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
Rich Helton
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
Rich Helton
 
Web Application Firewall intro
Web Application Firewall introWeb Application Firewall intro
Web Application Firewall intro
Rich Helton
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security Class
Rich Helton
 

More from Rich Helton (20)

Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02
 
NServicebus WCF Integration 101
NServicebus WCF Integration 101NServicebus WCF Integration 101
NServicebus WCF Integration 101
 
Azure rev002
Azure rev002Azure rev002
Azure rev002
 
Salesforce Intro
Salesforce IntroSalesforce Intro
Salesforce Intro
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad Programming
 
First Steps in Android
First Steps in AndroidFirst Steps in Android
First Steps in Android
 
NServiceBus
NServiceBusNServiceBus
NServiceBus
 
Python For Droid
Python For DroidPython For Droid
Python For Droid
 
Spring Roo Rev005
Spring Roo Rev005Spring Roo Rev005
Spring Roo Rev005
 
Python Final
Python FinalPython Final
Python Final
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 Final
 
Jira Rev002
Jira Rev002Jira Rev002
Jira Rev002
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 
Web Application Firewall intro
Web Application Firewall introWeb Application Firewall intro
Web Application Firewall intro
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security Class
 

Recently uploaded

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 

Mongo db rev001.

  • 1. MongoDB in C# By Rich Helton January 01, 2015 Buy “Mastering NserviceBus with Persistence”
  • 2. What is MongoDB MongoDB is a cross-platform document- oriented database. http://en.wikipedia.org/wiki/MongoDB ➢ This means that it is NoSQL, not utilizing the relational SQL commands, but utilizing JSON- like documents to query the database. ➢ The JSON-like documents are BSON, Binary JSON. ➢ MongoDB is free and open source. ➢ http://www.mongodb.org
  • 3. What is MongoDB ➢ MongoDB is a cross-platform document- oriented database. http://en.wikipedia.org/wiki/MongoDB ➢ This means that it is NoSQL, not utilizing the relational SQL commands, but utilizing JSON-like documents to query the database. ➢ MongoDB is free and open source. http://www.mongodb.org
  • 4. The Motivation ● Sometimes using a full Microsoft SQL Server installation, with maintenance for databases, may be a little overkill for something as simple as keeping track of a file history table. ● The need for access control is still needed for basic security, so something more than a File I/O is required.
  • 5. Installation ● Installation instructions can be found to install the correct version by checking the OS from http://docs.mongodb.org/manual/tutorial/insta ll-mongodb-on-windows/ ● The download page of the installations for Windows, OSX, Solaris and Linux can be found at http://www.mongodb.org/downloads ● We can optionally move the downloaded files to “C:mongodb”.
  • 6. Installation MSI's ● Alternately, you can just use the MongoDB MSI file to install the program into the “C:Program FilesMongoDB” directory. ● For Win32, http://dl.mongodb.org/dl/win32/i386 ● For Win64, http://dl.mongodb.org/dl/win32/x86_64
  • 7. Startup ● An data directory needs to be created to store the database, for example “md datadb”, which “datadb” is the default directory for mongod. ● Running “C:mongodbbinmongod.exe” will now create the database. ● The “--auth” argument can be used to force authentication into the server.
  • 9. There are many tools for MongoDB ➢ There are many admin tools, some can be found at http://docs.mongodb.org/ecosystem/tools/adm ➢ One of the admin tools that supports multiple platforms and runs in Java is Umongo, found at http://edgytech.com/umongo/
  • 10. Viewing the new database in UMongo After downloading Umongo, we run the applications with the default settings to see the new database:
  • 11. Running as a Service l To run MongoDB as a service, we need a config file and we will use the -install option on this config file. l We will create a log directory in the “C:datadb” directory.
  • 12. Creating and starting the service Running “mongod --logpath=C:datadblogmongo.log --install” as administrator in the command prompt:
  • 13. Viewing the service After installing the service, we can see the service running:
  • 14. A recap of some of the exe's: ● mongo.exe – runs the database shell. ● mongod.exe – the core database. ● mongos.exe – auto sharding process. ● mongodump.exe – dump/export utility. ● mongorestore.exe – restore/import utility.
  • 16. We will create a Command program MongoDBConsoleApp1
  • 18. No matter the database, there needs to be a connectionstring l Add an App.config with the “<add key="connectionString" value="Server=localhost:27017"/>”. The default port for MongoDB is port 27017.
  • 19. Starting the DB connection l We will get the connectionstring, and connect to the database.
  • 20. BSON and the DB In order to perform CRUD operations on the database, a BsonCollection is used to map to the table. The table is really a collection of documents. The documents being name/value pairs. Here, we have an insert of a document.
  • 21. More on BSON  BSON is Binary JSON.  It is a name-value pair, in which the value could be many different data types.  More on BSON can be found at http://en.wikipedia.org/wiki/BSON
  • 22. After the insert, verify  After the insert, we can verify the data in UMongo.  Here, we see that a document was created in the FileHistory collection.  We can also export the data to a text file.
  • 24. Code to read the collection  A table is just a collection of documents. Each document has a name/value pair.  We walk through the collection reading the name-value pair.
  • 25. Updating the collection ➢ To update the collection, find the value in the collection, change it, and save it in the collection.
  • 26. Deleting a document ➢ To remove a document, a query has to be developed that matches a name-value pair.
  • 27. Deleting a collection (table) ➢ To remove a collection, a drop need only be performed on the collection.
  • 28. static void Main(string[] args) { // get the App.config Connection String string connString = ConfigurationManager.AppSettings["connectionString"]; // Get the client connection var client = new MongoClient(connString); // Get the MongoServer Object var server = client.GetServer(); // Gets a link to the DB, will create with first insert MongoDatabase myDatabase = server.GetDatabase("FileHistory"); // Create a BsonDocument list for the Table MongoCollection<BsonDocument> filesReceivedTable = myDatabase.GetCollection<BsonDocument>("BankFilesReceieved"); // Create an individual Table row with the fields BsonDocument filesReceived = new BsonDocument { { "DateReceived", DateTime.Now }, { "FileName", "BankFile1.txt" }}; // Insert into table filesReceivedTable.Insert(filesReceived); // Get the table collection MongoCollection<BsonDocument> updateTable = myDatabase.GetCollection<BsonDocument>("BankFilesReceieved"); // Walk through each document updating the name-value pair. foreach (var filesRead in updateTable.FindAll()) { foreach (var elements in filesRead.Elements) { if (elements.Name == "FileName") { elements.Value = "BankNameChanged.txt"; updateTable.Save(filesRead); } } }
  • 29. // Get the table collection MongoCollection<BsonDocument> deletingRows = myDatabase.GetCollection<BsonDocument>("BankFilesReceieved"); // Remove on query where a name = a specific value deletingRows.Remove(Query.EQ("FileName","BankNameChanged.txt")); // Get the table collection MongoCollection<BsonDocument> readingTable = myDatabase.GetCollection<BsonDocument>("BankFilesReceieved"); // Walk through each document reading the name-value pair. foreach (var filesRead in readingTable.FindAll()) { foreach (var elements in filesRead.Elements) { Console.WriteLine("Name :" + elements.Name); Console.WriteLine("Value :" + elements.Value); } } // Get the table collection MongoCollection<BsonDocument> deletingTable = myDatabase.GetCollection<BsonDocument>("BankFilesReceieved"); // Delecting the table deletingTable.Drop(); }
  • 31. Mongo Shell ● The mongo.exe is used to execute shell commands. http://docs.mongodb.org/manual/reference/mongo-shell/ ● The shell commands can be used to show databases, users, collections, and also create the same.
  • 32. Adding a user ● Can be created using the “db.addUser(“user”,”password”) in the mongo shell.
  • 33. In C#, adding a user would be similar to:
  • 34. In C#, executing the function could be done as:
  • 35. In C#, finding all users would be similar to:
  • 36. In C#, finding all users would be similar to:
  • 37. User Roles ● Just because a user is added, doesn't mean that the user has assigned roles. ● We can see the roles to be added in the NoSQL Manager for MongoDB.
  • 39. The Mongo C# driver ● The documentation can be found at http://docs.mongodb.org/ecosystem/drivers/cs ● This was the nuget driver that we installed earlier as version 1.9.2. There are c-sharp community projects found at http://docs.mongodb.org/ecosystem/drivers/csh , one of which is MongoCola.
  • 40. MongoCola ● MongoCola is an c# open source Mongo Admin tool. ● The c-sharp source code for MongoCola can be found at https://github.com/magicdict/MagicMongoDBTool
  • 41. Some Admin Tools Homepages ● MongoCola Homepage http://osdig.com/project/index/id/22703.html#.VK ● No-SQL Manager for MongoDB http://www.mongodbmanager.com/

Editor's Notes

  1. Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important. Introduce each of the major topics. To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.