List of usage examples for com.mongodb DBCollection remove
public WriteResult remove(final DBObject query)
From source file:mini_mirc_server.miniIRCHandler.java
/** * Delete a user in all channel (used in cleaning) * @param Username/* w w w. j av a 2 s .c o m*/ * @return code */ public int DeleteUserInChannel(String Username) { int ret = 0; try { MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("channelCollection"); BasicDBObject query = new BasicDBObject("username", Username); DBCursor cursor = coll.find(query); try { while (cursor.hasNext()) { coll.remove(cursor.next()); } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(miniIRCHandler.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(Username + " has been deleted in Channel Collection!"); return ret; }
From source file:mini_mirc_server.miniIRCHandler.java
/** * Moved active user to a passive user (soon to be deleted) * @param username//from w w w. j a v a 2 s . c om * @return code */ public int SoftDelete(String username) { int ret = 0; try { MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("activeUser"); DBCollection coll2 = db.getCollection("passiveUser"); BasicDBObject query = new BasicDBObject("username", username); DBCursor cursor = coll.find(query); try { if (cursor.hasNext()) { DBObject temp = cursor.next(); coll2.insert(temp); coll.remove(temp); } else { ret = 1; } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(miniIRCHandler.class.getName()).log(Level.SEVERE, null, ex); } return ret; }
From source file:mini_mirc_server.miniIRCHandler.java
public String GetMessage(String username) { String ret = ""; try {// ww w . j av a 2 s . c o m MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("inbox"); BasicDBObject query = new BasicDBObject("target", username); JSONObject obj = new JSONObject(); JSONArray arr = new JSONArray(); DBCursor cursor = coll.find(query); try { while (cursor.hasNext()) { BasicDBObject temp = (BasicDBObject) cursor.next(); JSONObject sav = new JSONObject(); sav.put("target", temp.getString("target")); sav.put("username", temp.getString("username")); sav.put("channel", temp.getString("channel")); sav.put("message", temp.getString("message")); sav.put("timestamp", temp.getLong("timestamp")); arr.add(sav); coll.remove(temp); } obj.put("msg", arr); ret = obj.toJSONString(); } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(miniIRCHandler.class.getName()).log(Level.SEVERE, null, ex); } UpdateLastActive(username); return ret; }
From source file:model.DocumentoDAO.java
public static void removerPorNome(String nomeTexto) { DB db = ConnectionFactory.create();/*w w w .j ava2 s . c om*/ DBCollection coll = db.getCollection("documentos"); DBObject query = new BasicDBObject("nome", nomeTexto); DBObject resultado = coll.findOne(query); coll.remove(resultado); }
From source file:Modelo.DAO.MongoDAO.java
public static void borrarMongo() { try {//from ww w . j ava 2s .c om Conexion con = new Conexion(); mongoClient = con.conectarMongo(); } catch (UnknownHostException ex) { System.out.println("Imposible realizar la conexin: " + ex.getMessage()); } DB db = mongoClient.getDB("test"); DBCollection docs = db.getCollection("fotitos"); DBCursor cur2 = docs.find(); while (cur2.hasNext()) docs.remove(cur2.next()); }
From source file:models.datasource.SingletonDataSource.java
public static boolean deleteUser(String email) { DBCollection collection = connectDB("mongo.usersCollection"); BasicDBObject query = new BasicDBObject().append("email", email); DBObject dbObject = collection.findOne(query); if (dbObject != null) { collection.remove(dbObject); mongoClient.close();/*from w ww. j a v a 2 s . c o m*/ return true; } else { mongoClient.close(); return false; } }
From source file:Modules.Client.Model.DAO.DAO_Mongo_client.java
public static void remove_client(Client_class cli) { DBCollection table = Singleton_app.collection; table.remove(new BasicDBObject().append("dni", cli.getDni())); }
From source file:Modules.Client.Model.DAO.DAO_Mongo_client.java
public static void remove_client() { DBCollection table = Singleton_app.collection; Client_class cli = Singleton_client.cl; table.remove(new BasicDBObject().append("dni", cli.getDni())); }
From source file:Modules.Client.Model.DAO.DAO_Mongo_client.java
public static void remove_client_dni(String dni) { DBCollection table = Singleton_app.collection; table.remove(new BasicDBObject().append("dni", dni)); }
From source file:mongocrud.Delete.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/*from w w w. j av a2 s . c o m*/ DB UniDB = DBManager.getDatabase(); DBCollection table = UniDB.getCollection("student"); BasicDBObject query = new BasicDBObject("_id", new BasicDBObject("$eq", jTextField1.getText())); table.remove(query); JOptionPane.showMessageDialog(rootPane, "User Delete SucessFully...!"); this.setVisible(false); this.dispose(); } catch (Exception e) { e.printStackTrace(); } }