SlideShare una empresa de Scribd logo
1 de 10
+

MongoDB Java
Using JAVA API to use MongoDB

http://www.youtube.com/zarigatongy
+

Follow Me @
http://youtube.com/zarigatongy

http://www.youtube.com/zarigatongy
+ Using java with MongoDB
 Download
 Make

the Driver from the MongoDB website.

use of the below packages in your class

import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;

http://www.youtube.com/zarigatongy
+ Using java with MongoDB

Build the following document with
the help of JAVA API
> db.user.findOne()
{
"_id" : ObjectId("513f4b2b1257cc7801c09190"),

"fName" : "anish01",
"lName" : "nath01",
"family" : {

"fatherName" : "anil",
"motherName" : "Indu"
http://www.youtube.com/zarigatongy
+ Sample Java Programe
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
public class TestAddUser {
public static void main(String[] args) throws UnknownHostException {

/**
* Open up the connection in the MongoDB
*/
Mongo mongo = new Mongo();
/**
* use the user DB if not exist
http://www.youtube.com/zarigatongy

create it
+ Sample java Programe (Contd…)
/**
* Use BasicDBObject to create document
*/
BasicDBObject userDoc = new BasicDBObject();
userDoc.put("fName", "anish01");

userDoc.put("lName", "nath01");
BasicDBObject familyDetailsDoc = new BasicDBObject();
familyDetailsDoc.put("fatherName", "anil");
familyDetailsDoc.put("motherName", "Indu");
/* Attached to the family doc to the userDocument */

http://www.youtube.com/zarigatongy
+ Using java with MongoDB

Build the following document with
the help of JAVA API
> db.user.findOne()
{
"_id" : ObjectId("513f4eb21257b06b3cf186b6"),
"fName" : "anish01",
"lName" : "nath01",
"family" : {
"fatherName" : "anil",

"motherName" : "Indu"
},
http://www.youtube.com/zarigatongy
"remarks" : [
+

Sample Java Program 2
/* Create Mongo Instance and get the coolection */

BasicDBObject userDoc = new BasicDBObject();

userDoc.put("fName", "anish01");

userDoc.put("lName", "nath01");

BasicDBObject familyDetailsDoc = new BasicDBObject();

familyDetailsDoc.put("fatherName", "anil");

familyDetailsDoc.put("motherName", "Indu");

/* Attached to the family doc to the userDocument */

userDoc.put("family", familyDetailsDoc);

ArrayList<BasicDBObject> remarks = new ArrayList<BasicDBObject>();

remarks.add((BasicDBObject) BasicDBObjectBuilder.start()

.add("uName", "arjun").add("feedback", "good").get());

remarks.add((BasicDBObject) BasicDBObjectBuilder.start()

http://www.youtube.com/zarigatongy
.add("uName", "manisha").add("feedback", "bad").get());
+ Finding Data with query in Collection
public static void main(String[] args) throws UnknownHostException {
/**
* Open up the connection in the MongoDB
*/
Mongo mongo = new Mongo();
/**
* use the user DB if not exist create it
*/
DB db = mongo.getDB("user");
/**
* Lookup the user Document in collection
*/
http://www.youtube.com/zarigatongy

DBCollection userCollection = db.getCollection("user");
+ More Tutorial Available


how to hack websites Sql Injection Attack/prevention By
Example



How java serialization works internally, Object Serialization
algorithm



java in programming Solving Producer Consumer Problem



One line java program that throw
"java.lang.OutOfMemoryError: Java heap space Analysis
Eclipse MAT



thread dump analysis with lab,how to analyse deadlock
thread dump with jstack,kill command in java



wireshark tutorial,Top 5 features you must Know in 5
minutes

http://www.youtube.com/zarigatongy

Más contenido relacionado

Destacado

Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFDhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFzarigatongy
 
The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)zarigatongy
 
RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors zarigatongy
 
Top 10 programming langauges crossed decades
Top 10 programming langauges crossed decadesTop 10 programming langauges crossed decades
Top 10 programming langauges crossed decadeszarigatongy
 
Password Authentication Protocol
Password Authentication ProtocolPassword Authentication Protocol
Password Authentication Protocol zarigatongy
 
final Global outlook feb 2015
final Global outlook feb 2015final Global outlook feb 2015
final Global outlook feb 2015Julie McGovern
 
Pieter Porters Company Profile
Pieter Porters Company ProfilePieter Porters Company Profile
Pieter Porters Company ProfileBart Leirs
 
Peaks & Plains 5 Year Plan Final
Peaks & Plains 5 Year Plan FinalPeaks & Plains 5 Year Plan Final
Peaks & Plains 5 Year Plan FinalTim Pinder
 
Mat ii2014rosangela
Mat ii2014rosangelaMat ii2014rosangela
Mat ii2014rosangelaedinf
 
Derrick Man Asif JPG New
Derrick Man Asif JPG NewDerrick Man Asif JPG New
Derrick Man Asif JPG NewMuhammad Asif
 

Destacado (16)

Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFDhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
 
The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)The Point to Point Protocol (PPP)
The Point to Point Protocol (PPP)
 
RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors RADIUS- Packet Example/Vendors
RADIUS- Packet Example/Vendors
 
Top 10 programming langauges crossed decades
Top 10 programming langauges crossed decadesTop 10 programming langauges crossed decades
Top 10 programming langauges crossed decades
 
Password Authentication Protocol
Password Authentication ProtocolPassword Authentication Protocol
Password Authentication Protocol
 
final Global outlook feb 2015
final Global outlook feb 2015final Global outlook feb 2015
final Global outlook feb 2015
 
P & W Profile1
P & W Profile1P & W Profile1
P & W Profile1
 
Pieter Porters Company Profile
Pieter Porters Company ProfilePieter Porters Company Profile
Pieter Porters Company Profile
 
isg
isgisg
isg
 
Peaks & Plains 5 Year Plan Final
Peaks & Plains 5 Year Plan FinalPeaks & Plains 5 Year Plan Final
Peaks & Plains 5 Year Plan Final
 
Mat ii2014rosangela
Mat ii2014rosangelaMat ii2014rosangela
Mat ii2014rosangela
 
Kalemegdan
KalemegdanKalemegdan
Kalemegdan
 
20140609081654492
2014060908165449220140609081654492
20140609081654492
 
Clipping
ClippingClipping
Clipping
 
Derrick Man Asif JPG New
Derrick Man Asif JPG NewDerrick Man Asif JPG New
Derrick Man Asif JPG New
 
Wild Animals
Wild AnimalsWild Animals
Wild Animals
 

Último

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Mongo db java

  • 1. + MongoDB Java Using JAVA API to use MongoDB http://www.youtube.com/zarigatongy
  • 3. + Using java with MongoDB  Download  Make the Driver from the MongoDB website. use of the below packages in your class import com.mongodb.Mongo; import com.mongodb.DB; import com.mongodb.DBCollection; http://www.youtube.com/zarigatongy
  • 4. + Using java with MongoDB Build the following document with the help of JAVA API > db.user.findOne() { "_id" : ObjectId("513f4b2b1257cc7801c09190"), "fName" : "anish01", "lName" : "nath01", "family" : { "fatherName" : "anil", "motherName" : "Indu" http://www.youtube.com/zarigatongy
  • 5. + Sample Java Programe import java.net.UnknownHostException; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.Mongo; public class TestAddUser { public static void main(String[] args) throws UnknownHostException { /** * Open up the connection in the MongoDB */ Mongo mongo = new Mongo(); /** * use the user DB if not exist http://www.youtube.com/zarigatongy create it
  • 6. + Sample java Programe (Contd…) /** * Use BasicDBObject to create document */ BasicDBObject userDoc = new BasicDBObject(); userDoc.put("fName", "anish01"); userDoc.put("lName", "nath01"); BasicDBObject familyDetailsDoc = new BasicDBObject(); familyDetailsDoc.put("fatherName", "anil"); familyDetailsDoc.put("motherName", "Indu"); /* Attached to the family doc to the userDocument */ http://www.youtube.com/zarigatongy
  • 7. + Using java with MongoDB Build the following document with the help of JAVA API > db.user.findOne() { "_id" : ObjectId("513f4eb21257b06b3cf186b6"), "fName" : "anish01", "lName" : "nath01", "family" : { "fatherName" : "anil", "motherName" : "Indu" }, http://www.youtube.com/zarigatongy "remarks" : [
  • 8. + Sample Java Program 2 /* Create Mongo Instance and get the coolection */ BasicDBObject userDoc = new BasicDBObject(); userDoc.put("fName", "anish01"); userDoc.put("lName", "nath01"); BasicDBObject familyDetailsDoc = new BasicDBObject(); familyDetailsDoc.put("fatherName", "anil"); familyDetailsDoc.put("motherName", "Indu"); /* Attached to the family doc to the userDocument */ userDoc.put("family", familyDetailsDoc); ArrayList<BasicDBObject> remarks = new ArrayList<BasicDBObject>(); remarks.add((BasicDBObject) BasicDBObjectBuilder.start() .add("uName", "arjun").add("feedback", "good").get()); remarks.add((BasicDBObject) BasicDBObjectBuilder.start() http://www.youtube.com/zarigatongy .add("uName", "manisha").add("feedback", "bad").get());
  • 9. + Finding Data with query in Collection public static void main(String[] args) throws UnknownHostException { /** * Open up the connection in the MongoDB */ Mongo mongo = new Mongo(); /** * use the user DB if not exist create it */ DB db = mongo.getDB("user"); /** * Lookup the user Document in collection */ http://www.youtube.com/zarigatongy DBCollection userCollection = db.getCollection("user");
  • 10. + More Tutorial Available  how to hack websites Sql Injection Attack/prevention By Example  How java serialization works internally, Object Serialization algorithm  java in programming Solving Producer Consumer Problem  One line java program that throw "java.lang.OutOfMemoryError: Java heap space Analysis Eclipse MAT  thread dump analysis with lab,how to analyse deadlock thread dump with jstack,kill command in java  wireshark tutorial,Top 5 features you must Know in 5 minutes http://www.youtube.com/zarigatongy

Notas del editor

  1. { &quot;_id&quot; : ObjectId(&quot;513f4b2b1257cc7801c09190&quot;), &quot;fName&quot; : &quot;anish01&quot;, &quot;lName&quot; : &quot;nath01&quot;, &quot;family&quot; : { &quot;fatherName&quot; : &quot;anil&quot;, &quot;motherName&quot; : &quot;Indu&quot; }}