Example #1
0
 // same method as insert except save() is replaced by remove()
 public void delete(Receipt receipt) {
   try {
     BasicDBObject basicDBObject = toBasicDBObject(receipt);
     DB db = MongoDBCreater.getDB("MyDB");
     DBCollection collection = db.getCollection("MyCollection");
     collection.remove(basicDBObject);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #2
0
 // For debug purposes
 public void printAll(Receipt receipt) {
   try {
     DB db = MongoDBCreater.getDB("MyDB");
     DBCollection collection = db.getCollection("MyCollection");
     DBCursor cursor = collection.find();
     while (cursor.hasNext()) {
       System.out.println(cursor.next());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #3
0
 public void update(Receipt receipt) {
   try {
     BasicDBObject searchQuery = new BasicDBObject();
     searchQuery.put("id", receipt.getId());
     BasicDBObject basicDBObject = toBasicDBObject(receipt);
     DB db = MongoDBCreater.getDB("MyDB");
     DBCollection collection = db.getCollection("MyCollection");
     collection.update(searchQuery, basicDBObject);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }