List of usage examples for com.mongodb DBCollection find
public DBCursor find(@Nullable final DBObject query, final DBCollectionFindOptions options)
From source file:Vehicle_type_check.java
private void bike_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bike_buttonActionPerformed // TODO add your handling code here: try {//from w w w . j a v a 2 s.com int count_bike; System.out.println("Hello_End"); MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); if (count_bike < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } catch (Exception e) { } }
From source file:Vehicle_type_check.java
private void other_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_other_buttonActionPerformed // TODO add your handling code here: try {//from w w w . j a va 2 s.co m int count_other; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); if (count_other < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking Trucks"); } } catch (Exception e) { } }
From source file:Vehicle_type_check.java
private void car_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_car_buttonActionPerformed // TODO add your handling code here: try {/*from w w w .jav a 2 s .c o m*/ int count_car; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); if (count_car < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } catch (Exception e) { } }
From source file:Entry_OR_Exit.java
private void Entry_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Entry_buttonActionPerformed // TODO add your handling code here: /*/*from w ww.j a v a 2 s . c o m*/ setVisible(false); new Vehicle_type_check().setVisible(true); */ try { MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); if (radio_vehicle_check == -99) JOptionPane.showMessageDialog(null, "Please Chhose Vehicle Type"); else { if (radio_vehicle_check == 2) { int count_bike; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); if (count_bike < 50) { /*BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection.update(searchUpdate, UpdateObject); */ setVisible(false); new Veehicle_entry(radio_vehicle_check).setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } else if (radio_vehicle_check == 4) { int count_car; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); if (count_car < 50) { /* BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4",count_car+1)); collection.update(searchUpdate, UpdateObject); */ setVisible(false); new Veehicle_entry(radio_vehicle_check).setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } else { int count_other; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); if (count_other < 50) { /* BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other + 1)); collection.update(searchUpdate, UpdateObject); */ setVisible(false); new Veehicle_entry(radio_vehicle_check).setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking Trucks"); } } } } catch (Exception e) { } }
From source file:Entry_OR_Exit.java
private void Exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit_buttonActionPerformed // TODO add your handling code here: try {/*from www . j a v a 2s. c o m*/ MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); if (radio_vehicle_check == -99) JOptionPane.showMessageDialog(null, "Please Chhose Vehicle Type"); else { if (radio_vehicle_check == 2) { int count_bike; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); if (count_bike == 0) { JOptionPane.showMessageDialog(null, "No 2 Wheelers in the Parking!"); } else { setVisible(false); new Vehicle_exit(radio_vehicle_check).setVisible(true); } } else if (radio_vehicle_check == 4) { int count_car; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); if (count_car == 0) { JOptionPane.showMessageDialog(null, "No 4 Wheelers in the Parking!"); } else { setVisible(false); new Vehicle_exit(radio_vehicle_check).setVisible(true); } } else { int count_other; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); if (count_other == 0) { JOptionPane.showMessageDialog(null, "No Others in the Parking!"); } else { setVisible(false); new Vehicle_exit(radio_vehicle_check).setVisible(true); } } } } catch (Exception e) { System.err.println(e); } }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getAllCollectionUUIDs(DBCollection collection) { List<Long> ids = new ArrayList<Long>(); BasicDBObject query = new BasicDBObject(); BasicDBObject keys = new BasicDBObject(); keys.put("_id", 1); // 0 means exclude, rest are included DBCursor cur = collection.find(query, keys); while (cur.hasNext()) { DBObject o = cur.next();/*from w w w . j av a 2s .c o m*/ long uuid = (Integer) o.get("_id"); // checked: db type IS int ids.add(uuid); } cur.close(); return ids; }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * List all the documents in a Mongo collection * @param collName the name of the collection * @param key the document key to retrieve by * @return a String array of document keys * @throws DbException /*from ww w . j av a2 s . co m*/ */ @Override public String[] listCollectionByKey(String collName, String key) throws DbException { try { connect(); } catch (Exception e) { throw new DbException(e); } DBCollection coll = getCollectionFromName(collName); BasicDBObject keys = new BasicDBObject(); keys.put(key, 1); DBCursor cursor = coll.find(new BasicDBObject(), keys); if (cursor.length() > 0) { String[] docs = new String[cursor.length()]; Iterator<DBObject> iter = cursor.iterator(); int i = 0; while (iter.hasNext()) { Object obj = iter.next().get(key); docs[i++] = obj.toString(); } return docs; } else throw new DbException("no docs in collection " + collName); }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * Make a subset of the documents by a given subkey and value, * then retrieve all the values of the field * @param collection the collection to search * @param subKey the subKey to make the initial choice * @param subValue the value of the subKey to search for * @param fields the field names to retrieve * @return and array of field values as JSON object strings * @throws DbException /*from ww w . java 2s .c o m*/ */ @Override public String[] listCollectionBySubKey(String collection, String subKey, String subValue, String[] fields) throws DbException { try { connect(); DBCollection coll = getCollectionFromName(collection); DBObject query = new BasicDBObject(subKey, subValue); BasicDBObject keys = new BasicDBObject(); for (int i = 0; i < fields.length; i++) keys.put(fields[i], 1); DBCursor cursor = coll.find(query, keys); if (cursor.length() > 0) { String[] array = new String[cursor.length()]; Iterator iter = cursor.iterator(); int i = 0; while (iter.hasNext()) { DBObject bson = (DBObject) iter.next(); JSONObject jobj = new JSONObject(); for (int j = 0; j < fields.length; j++) jobj.put(fields[j], bson.get(fields[j])); array[i++] = jobj.toJSONString(); } return array; } else return new String[0]; } catch (Exception e) { throw new DbException(e); } }
From source file:calliope.core.database.MongoConnection.java
License:Open Source License
/** * List all the documents in a Mongo collection * @param collName the name of the collection * @param key the document key to retrieve by * @return a String array of document keys * @throws DbException //from w w w .j a v a 2 s .c om */ @Override public String[] listCollectionByKey(String collName, String key) throws DbException { try { connect(); } catch (Exception e) { throw new DbException(e); } DBCollection coll = getCollectionFromName(collName); BasicDBObject keys = new BasicDBObject(); keys.put(key, 1); DBCursor cursor = coll.find(new BasicDBObject(), keys); if (cursor.length() > 0) { String[] docs = new String[cursor.length()]; Iterator<DBObject> iter = cursor.iterator(); int i = 0; while (iter.hasNext()) { DBObject dbObj = iter.next(); Object obj = dbObj.get(key); if (key.equals(JSONKeys._ID)) { ObjectId id = (ObjectId) dbObj.get(JSONKeys._ID); obj = id.toStringMongod(); docs[i++] = (String) obj; } else docs[i++] = obj.toString(); } return docs; } else return new String[0]; }
From source file:calliope.core.database.MongoConnection.java
License:Open Source License
/** * List all the documents in a Mongo collection * @param collName the name of the collection * @return a String array of document keys * @throws DbException //from w ww. j av a2s . co m */ @Override public String[] listCollection(String collName) throws DbException { try { connect(); } catch (Exception e) { throw new DbException(e); } DBCollection coll = getCollectionFromName(collName); BasicDBObject keys = new BasicDBObject(); keys.put(JSONKeys.DOCID, 1); DBCursor cursor = coll.find(new BasicDBObject(), keys); if (cursor.length() > 0) { String[] docs = new String[cursor.length()]; Iterator<DBObject> iter = cursor.iterator(); int i = 0; while (iter.hasNext()) docs[i++] = (String) iter.next().get(JSONKeys.DOCID); return docs; } else return new String[0]; }