List of usage examples for com.mongodb DBCollection find
public DBCursor find(final DBObject query)
From source file:com.deliveronthego.DbConnection.java
public String customerSignup(String firstName, String lastName, String emailId, String password, int phoneNumber, String regId) { mongoclient = getConnection();/* w w w. j a v a 2s .co m*/ @SuppressWarnings("deprecation") DB database = mongoclient.getDB("deliveronthego"); DBCollection customerSignUpInfo = database.getCollection("login"); if (emailId.contains("@") && (password.length() <= 8) && (String.valueOf(phoneNumber).length() == 10)) { BasicDBObject customerSignUpInfoObj = new BasicDBObject("emailId", emailId).append("password", password); DBCursor customerSignUpInfoCur = customerSignUpInfo.find(customerSignUpInfoObj); if (customerSignUpInfoCur.hasNext()) { return "Customer Sign Up Info Already Exists"; } else { customerSignUpInfoObj.append("firstName", firstName).append("lastName", lastName) .append("phoneNumber", phoneNumber).append("userType", "User").append("regId", regId); customerSignUpInfo.insert(customerSignUpInfoObj); return "Customer Signup Info inserted successfully"; } } else { return "Customer SignUp Info failed to insert"; } }
From source file:com.deliveronthego.DbConnection.java
public String driverSignup(String firstName, String lastName, String driverLicense, String emailId, String password, int phoneNumber, String regId) { mongoclient = getConnection();//ww w . j av a 2 s .co m DB db = mongoclient.getDB("deliveronthego"); DBCollection driverSignUpInfo = db.getCollection("login"); if (emailId.contains("@") && (password.length() <= 8) && (String.valueOf(phoneNumber).length() == 10) && !driverLicense.isEmpty()) { BasicDBObject driverSignUpInfoObj = new BasicDBObject("driverLicense", driverLicense) .append("emailId", emailId).append("password", password); DBCursor driverSignUpInfoCur = driverSignUpInfo.find(driverSignUpInfoObj); if (driverSignUpInfoCur.hasNext()) { return "Driver Sign Up Info Already Exists"; } else { driverSignUpInfoObj.append("firstName", firstName).append("lastName", lastName) .append("phoneNumber", phoneNumber).append("userType", "Driver").append("regId", regId); driverSignUpInfo.insert(driverSignUpInfoObj); return "Driver Sign Up Info Inserted Successfully"; } } else { return "Driver SignUp Info failed to insert"; } }
From source file:com.deliveronthego.DbConnection.java
public boolean login(String emailId, String password, String userType) { mongoclient = getConnection();/* www . j a v a 2s . c o m*/ @SuppressWarnings("deprecation") DB db = mongoclient.getDB("deliveronthego"); DBCollection login = db.getCollection("login"); if (emailId.contains("@")) { BasicDBObject logInObj = new BasicDBObject(); logInObj.put("emailId", emailId); DBCursor logInCursor = login.find(logInObj); while (logInCursor.hasNext()) { logInCursor.next(); DBObject userDetailObj = logInCursor.curr(); if (userDetailObj != null) { String logInPassword = userDetailObj.get("password").toString(); String loginUserType = userDetailObj.get("userType").toString(); System.out.println(logInPassword); if ((logInPassword != null) && (logInPassword.equalsIgnoreCase(password)) && (loginUserType != null) && (loginUserType.equalsIgnoreCase(userType))) { return true; } else { return false; } } else { return false; } } return true; } else { return false; } }
From source file:com.deliveronthego.DbConnection.java
public String location(String date, double transitionLatitude, double transitionLongitude, double stopLatitude, double stopLongitude, String driverId) { mongoclient = getConnection();/*from w w w . j av a 2 s .c o m*/ @SuppressWarnings("deprecation") DB db = mongoclient.getDB("deliveronthego"); DBCollection location = db.getCollection("location"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("driverID", driverId); DBCursor locationCursor = location.find(whereQuery); boolean updateFlag = false; while (locationCursor.hasNext()) { locationCursor.next(); DBObject locDB = locationCursor.curr(); System.out.println(locDB); String dateStr = locDB.get("Date").toString(); if (dateStr.equals(date)) { location.update(new BasicDBObject("driverID", driverId), new BasicDBObject("$set", new BasicDBObject("transitionLatitude", transitionLatitude) .append("transitionLongitude", transitionLongitude))); Double previousStopLatitude = (Double) locDB.get("stopLatitude"); Double previousStopLongitude = (Double) locDB.get("stopLongitude"); System.out.println("previousStopLatitude: " + previousStopLatitude); System.out.println("previousStopLongitude: " + previousStopLongitude); /*if((previousStopLatitude==0.0) && (previousStopLongitude==0.0)) { location.update(new BasicDBObject("driverID", driverId), new BasicDBObject("$set", new BasicDBObject("stopLatitude", stopLatitude).append("stopLongitude", stopLongitude))); }*/ } updateFlag = true; } if (!updateFlag) { BasicDBObject locationObj = new BasicDBObject("Date", date.toString()) .append("transitionLatitude", transitionLatitude) .append("transitionLongitude", transitionLongitude).append("stopLatitude", stopLatitude) .append("stopLongitude", stopLongitude).append("driverID", driverId); location.insert(locationObj); return "Location Details Inserted Sucessfully"; } else { return "Location Details Updated"; } }
From source file:com.deliveronthego.DbConnection.java
public String transcationNotification(String driverID, Boolean pickedUp, Boolean delivered) { mongoclient = getConnection();//from ww w .ja v a 2s .co m @SuppressWarnings("deprecation") DB db = mongoclient.getDB("deliveronthego"); DBCollection notification = db.getCollection("notification"); BasicDBObject notificationObj = new BasicDBObject(); notificationObj.append("driverID", driverID); Date date = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date); DBCursor notificationCursor = notification.find(notificationObj); if (pickedUp && !delivered) { notificationObj.append("pickedUp", pickedUp.toString()).append("delivered", delivered.toString()) .append("date", cal.toString()); notification.insert(notificationObj); return "New Transaction Data inserted"; } else { if (notificationCursor.hasNext()) { notificationCursor.next(); DBObject notifyObj = notificationCursor.curr(); Date currentDateInDatabase = (Date) notifyObj.get("date"); if (!(boolean) notifyObj.get("delivered") && currentDateInDatabase.before(date)) { notification.update(new BasicDBObject("driverID", driverID), new BasicDBObject("$set", new BasicDBObject("delivered", delivered.toString()))); return "Transaction Completed"; } else { return "Transaction failed to update"; } } else { return "Transaction failed"; } } }
From source file:com.ebay.cloud.cms.metadata.dataloader.MetadataDataLoader.java
License:Apache License
private List<String> getAllRepositoryNames() { DBCollection repoCollection = this.mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.REPOSITORY_COLL); BasicDBObject query = new BasicDBObject(); List<String> repoNameList = new ArrayList<String>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject bsonObject = cursor.next(); String repoName = (String) bsonObject.get(Repository.REPOSITORY_FIELD_NAME); repoNameList.add(repoName);/*from w w w . j av a2 s. co m*/ } return repoNameList; }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
void refreshTagRangeList() { String ns = getCollectionNode().getCollection().getFullName(); ListArea list = (ListArea) getBoundUnit(Item.tagRangeList); final DB config = getCollectionNode().getCollection().getDB().getSisterDB("config"); final DBCollection col = config.getCollection("tags"); DBCursor cur = col.find(new BasicDBObject("ns", ns)); ArrayList<String> ranges = new ArrayList<String>(); while (cur.hasNext()) { BasicDBObject range = (BasicDBObject) cur.next(); ranges.add(MongoUtils.getJSON(range)); }// w ww .j a v a 2s .c om list.items = ranges.toArray(new String[ranges.size()]); list.structureComponent(); }
From source file:com.emuneee.camerasyncmanager.util.DatabaseUtil.java
License:Apache License
/** * Returns a camera with id//from w w w . j a v a 2 s . co m * @param id * @return */ public Camera getCamera(String id) { Camera camera = null; DB db = getDatabase(); DBCursor cursor = null; try { DBCollection collection = db.getCollection("camera"); BasicDBObject query = new BasicDBObject("_id", id); cursor = collection.find(query); if (cursor.hasNext()) { BasicDBObject dbObj = (BasicDBObject) cursor.next(); camera = dbObjectToCamera(dbObj); } } catch (Exception e) { sLogger.error("Exception retrieving camera with id " + id); sLogger.error(e); } finally { HttpHelper.closeResources(new Object[] { cursor }); } return camera; }
From source file:com.ewcms.mongo.demo.repositories.PersonRepositoryImpl.java
License:Open Source License
@Override public List<Person> findWorkByAgeRang(final int start, final int end) { return getMongoOperations().execute(new DbCallback<List<Person>>() { @Override/*ww w.j a v a 2s . co m*/ public List<Person> doInDB(DB db) throws MongoException, DataAccessException { DBCollection coll = db.getCollection("person"); BasicDBObject query = new BasicDBObject(); query.put("age", new BasicDBObject("$gte", 20).append("$lte", 60)); DBCursor cur = coll.find(query); List<Person> list = new ArrayList<Person>(); for (; cur.hasNext();) { DBObject source = cur.next(); Person person = convertEntity(source); list.add(person); } return list; } }); }
From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java
public String query(Hashtable conditions) { List<DBObject> list = null; DB myDB = getDB(DB_NAME);/*from w ww .ja v a 2 s . c om*/ DBCollection coll = myDB.getCollection("projects"); BasicDBObject cond = new BasicDBObject(); Set<String> keySet = conditions.keySet(); Iterator<String> it = keySet.iterator(); while (it.hasNext()) { String key = it.next(); String value = (String) conditions.get(key); if (value == null || value.equals("All")) { continue; } Pattern pattern = null; if (key.equals("Project_Phase")) { if (value.equals("Ongoing")) { BasicDBList dlist = new BasicDBList(); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Completed"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Eng-Complete"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Canceled"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Publication"))); cond.append("$and", dlist); } else if (value.equals("Complete")) { ArrayList<String> slist = new ArrayList(); slist.add("Completed"); slist.add("Eng-Complete"); slist.add("Publication"); cond.append(key, new BasicDBObject("$in", slist)); //Limited to FY15 projects //pattern = Pattern.compile("^.*15-\\[.*$", Pattern.CASE_INSENSITIVE); //Limited to FY16 projects pattern = Pattern.compile("^.*16-.*$", Pattern.CASE_INSENSITIVE); cond.append("ISVe_Goal", pattern); } } else if (key.equals("Keywords") && value.equals("Non-OPI")) { // not like 'OPI' pattern = Pattern.compile("^((?!OPI).)*$", Pattern.CASE_INSENSITIVE); cond.append(key, pattern); } else { // like '*OPI*' pattern = Pattern.compile("^.*" + value + ".*$", Pattern.CASE_INSENSITIVE); cond.append(key, pattern); } System.out.println(key + ":" + value); } DBCursor ret = coll.find(cond); BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1); ret.sort(sort); try { list = ret.toArray(); } finally { ret.close(); } //System.out.println(list.toString()); return list.toString(); }