List of usage examples for com.mongodb DBCollection find
public DBCursor find(final DBObject query)
From source file:com.tml.pathummoto.Dao.CustomDao.java
public Customer searchCustomer(String no) { Customer customer = new Customer(); // To connect to mongodb server MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("customer"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("_id", no); DBCursor cursor = coll.find(whereQuery); while (cursor.hasNext()) { System.out.println(cursor.next()); }/*from w w w. j av a 2 s .com*/ BasicDBObject doc = (BasicDBObject) cursor.curr(); System.out.println("doc" + doc); if (doc != null) { customer.setVehicleNo(doc.getString("_id")); customer.setName(doc.getString("name")); customer.setPayment(doc.getInt("payment")); customer.setFreeServiceNo(doc.getInt("freeServiceNo")); customer.setServiceNo(doc.getInt("serviceNo")); customer.setDateOfDelivery(doc.getDate("dateOfDelivery")); customer.setLastKm(doc.getInt("lastKm")); } return customer; }
From source file:com.tml.pathummoto.Dao.CustomDao.java
public void updateCustomer(Customer customer) { MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("customer"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("_id", customer.getVehicleNo()); DBCursor cursor = coll.find(whereQuery); System.out.println(customer.getVehicleNo()); DBObject query = new BasicDBObject("_id", customer.getVehicleNo()); DBObject update = new BasicDBObject(); update.put("$set", new BasicDBObject("payment", customer.getPayment()) .append("freeServiceNo", customer.getFreeServiceNo()).append("serviceNo", customer.getServiceNo()) .append("dateOfDelivery", customer.getDateOfDelivery()).append("lastKm", customer.getLastKm())); WriteResult result = coll.update(query, update); System.out.println(result);//from w ww.j a va 2 s .c o m }
From source file:com.tml.pathummoto.Dao.PartDao.java
public Part searchPart(String partNo) { Part part = new Part(); MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("part"); System.out.println("Collection part selected successfully"); BasicDBObject find = new BasicDBObject(); find.put("_id", partNo); DBCursor cursor = coll.find(find); while (cursor.hasNext()) { System.out.println(cursor.next()); }//from ww w. j a va 2 s . c om BasicDBObject doc = (BasicDBObject) cursor.curr(); if (doc != null) { } return part; }
From source file:com.tml.pathummoto.Dao.PartDao.java
public Part singlePart(String partNumber) { Part part = new Part(); // To connect to mongodb server MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("part"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("_id", partNumber); DBCursor cursor = coll.find(whereQuery); while (cursor.hasNext()) { System.out.println(cursor.next()); }/*from ww w .j av a 2 s . com*/ BasicDBObject doc = (BasicDBObject) cursor.curr(); if (doc != null) { part.setPartName(doc.getString("Part Name")); part.setPartNo(doc.getString("_id")); } return part; }
From source file:com.tml.pathummoto.Dao.PartDao.java
public ArrayList getMainPartData(String name) { MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("mainpart"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("Model Name", name); DBCursor cursor = coll.find(whereQuery); ArrayList arr = new ArrayList(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); arr.add(obj.getString("Part Type")); }/*from w w w . j a va 2 s. c om*/ return (arr); }
From source file:com.tml.pathummoto.Dao.PartDao.java
public String getImage(String model, String mainPart) { String path = "C:\\Users\\Tishan Madhawa\\Pictures\\WP_20160118_17_31_47_Pro.jpg"; MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("mainpart"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("Model Name", model); whereQuery.put("Part Type", mainPart); DBCursor cursor = coll.find(whereQuery); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); path = obj.getString("path"); }/*from w w w.java 2 s . c om*/ System.out.println(path); return path; }
From source file:com.tml.pathummoto.Dao.PartDao.java
public ArrayList searchParts(String model, String mainPart) { MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("part"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("Model Name", model); whereQuery.put("Part Type", mainPart); DBCursor cursor = coll.find(whereQuery); ArrayList<Part> arr = new ArrayList<Part>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); Part part = new Part(obj.getString("Image No"), obj.getString("_id"), obj.getString("Part Name")); arr.add(part);//from ww w . j a va2 s . co m System.out.println(arr); } return (arr); }
From source file:com.tml.pathummoto.Dao.PartDao.java
public ArrayList searchpart3(String modelName, String PartType) { MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("part"); System.out.println("Collection user selected successfully"); System.out.println(modelName); System.out.println(PartType); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("Model Name", modelName); whereQuery.put("Part Type", PartType); DBCursor cursor = coll.find(whereQuery); ArrayList<Part> arr = new ArrayList<Part>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); Part part = new Part(obj.getString("Part Name"), obj.getString("_id"), obj.getString("Part Type"), obj.getInt("quant")); // System.out.println(obj.getString("Image No").toString()); arr.add(part);/* w w w . j a v a 2 s .c om*/ } return (arr); }
From source file:com.tml.pathummoto.Dao.PartDao.java
public ArrayList searchpart4(String modelName, String PartType) { MongoClient mongoClient = new MongoClient("localhost", 27017); // // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("part"); System.out.println("Collection user selected successfully"); System.out.println(modelName); System.out.println(PartType); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("Model Name", modelName); whereQuery.put("Part Type", PartType); DBCursor cursor = coll.find(whereQuery); ArrayList<Part> arr = new ArrayList<Part>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); Part part;/*www.ja v a 2s .c om*/ part = new Part(obj.getString("Quantity"), obj.getString("_id"), obj.getInt("quant")); arr.add(part); } return (arr); }
From source file:com.tml.pathummoto.Dao.UserDao.java
public User login(String name) { User user = new User(); // To connect to mongodb server MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("pathumdb"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("user"); System.out.println("Collection user selected successfully"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("title", name); DBCursor cursor = coll.find(whereQuery); while (cursor.hasNext()) { System.out.println(cursor.next()); }/*from ww w. ja v a2s .com*/ BasicDBObject doc = (BasicDBObject) cursor.curr(); if (doc != null) { user.setName(doc.getString("title")); user.setPassword(doc.getString("password")); } return user; }