SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

En vedette

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
 

En vedette (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
 

Dernier

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Dernier (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

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

Notes de l'éditeur

  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; }}