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