List of usage examples for com.mongodb.client MongoCollection deleteOne
DeleteResult deleteOne(Bson filter);
From source file:com.eclipsesource.connect.persistence.MongoStorage.java
License:Open Source License
@Override public void delete(String place, Object object, Object... objects) { validateArguments(place, object);// w w w.j av a2 s . c o m MongoDatabase db = factory.getDB(); MongoCollection<Document> collection = db.getCollection(place); List<Document> documents = createDocuments(object, objects); documents.forEach(document -> collection.deleteOne(new Document(KEY_ID, document.get(KEY_ID)))); }
From source file:com.eclipsesource.connect.test.util.persistence.InMemoryStorage.java
License:Open Source License
@Override public void delete(String place, Object object, Object... objects) { validateArguments(place, object);/*from w w w .jav a2 s . c o m*/ MongoCollection<Document> collection = db.getCollection(place); List<Document> documents = createDocuments(object, objects); documents.forEach(document -> collection.deleteOne(new Document(KEY_ID, document.get(KEY_ID)))); }
From source file:com.eightkdata.mongowp.client.wrapper.MongoConnectionWrapper.java
License:Open Source License
@Override public void asyncDelete(String database, String collection, boolean singleRemove, BsonDocument selector) throws MongoException { try {/*from w w w . j av a2 s . com*/ MongoCollection<BsonDocument> collectionObject = owner.getDriverClient().getDatabase(database) .getCollection(collection, BsonDocument.class); org.bson.BsonDocument mongoSelector = MongoBsonTranslator.translate(selector); if (singleRemove) { collectionObject.deleteOne(mongoSelector); } else { collectionObject.deleteMany(mongoSelector); } } catch (com.mongodb.MongoException ex) { //a general Mongo driver exception if (ErrorCode.isErrorCode(ex.getCode())) { throw toMongoException(ex); } else { throw toRuntimeMongoException(ex); } } catch (IOException ex) { throw new BadValueException("Unexpected IO exception", ex); } }
From source file:com.epam.dlab.auth.dao.UserInfoDAOMongoImpl.java
License:Apache License
@Override public void deleteUserInfo(String accessToken) { //delete used in logout and has to be synchronized BasicDBObject uiDoc = new BasicDBObject(); uiDoc.put("_id", accessToken); MongoCollection<BasicDBObject> security = ms.getCollection("security", BasicDBObject.class); security.deleteOne(uiDoc); log.debug("Deleted persistent {}", accessToken); }
From source file:com.gs.obevo.mongodb.impl.MongoDbChangeAuditDao.java
License:Apache License
@Override public void deleteChange(Change change) { MongoCollection<Document> auditCollection = getAuditCollection(change); auditCollection.deleteOne(Filters.and(Filters.eq(changeNameColumn, change.getChangeName()), Filters.eq("OBJECTNAME", change.getObjectName()))); }
From source file:com.gs.obevo.mongodb.impl.MongoDbChangeAuditDao.java
License:Apache License
@Override public void deleteObjectChanges(Change change) { MongoCollection<Document> auditCollection = getAuditCollection(change); auditCollection.deleteOne(Filters.eq("OBJECTNAME", change.getObjectName())); }
From source file:com.spleefleague.bungee.io.EntityBuilder.java
public static void delete(DBEntity object, MongoCollection<Document> dbcoll) { dbcoll.deleteOne(new Document("_id", object.getObjectId())); }
From source file:com.threecrickets.prudence.cache.HazelcastMongoDbMapStore.java
License:LGPL
public void delete(K key) { MongoCollection<Document> collection = getCollection(); Document query = new Document(); query.put("_id", key); collection.deleteOne(query); }
From source file:com.torodb.mongowp.client.wrapper.MongoConnectionWrapper.java
License:Apache License
@Override public void asyncDelete(String database, String collection, boolean singleRemove, BsonDocument selector) throws MongoException { try {//from ww w. j a va 2s .c om MongoCollection<BsonDocument> collectionObject = owner.getDriverClient().getDatabase(database) .getCollection(collection, BsonDocument.class); org.bson.BsonDocument mongoSelector = MongoBsonTranslator.translate(selector); if (singleRemove) { collectionObject.deleteOne(mongoSelector); } else { collectionObject.deleteMany(mongoSelector); } } catch (com.mongodb.MongoException ex) { //a general Mongo driver exception if (ErrorCode.isErrorCode(ex.getCode())) { throw toMongoException(ex); } else { throw toRuntimeMongoException(ex); } } }
From source file:Controlador.Controlador.java
private void control() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { //SORTIR if (actionEvent.getSource().equals(vista.getjButton6())) { System.out.println("Sortint... ADEU!"); System.exit(0);/*from www . j a v a 2 s.c o m*/ } //SORTIR DB if (actionEvent.getSource().equals(vistaDB.getjButton2())) { System.out.println("Sortint... ADEU!"); System.exit(0); } //Carrega Coleccions DB if (actionEvent.getSource().equals(vistaDB.getjButton1())) { carregarColections(); vistaDB.setVisible(false); vista.setVisible(true); } //Actualitzar document if (actionEvent.getSource().equals(vista.getjButton2())) { Document d = Document.parse(vista.getjTextArea1().getText()); System.out.println(d); try { MongoCollection col = model.getDatabase() .getCollection(vista.getjList1().getSelectedValue()); //UpdateResult resultat = col.updateOne(eq("i", 10), set("i", 110)); } catch (Exception e) { } } //Inserir documents sencers if (actionEvent.getSource().equals(vista.getjButton1())) { MongoCollection col = model.getMongoClient().getDatabase(vistaDB.getjList1().getSelectedValue()) .getCollection(vista.getjList1().getSelectedValue()); Document d = Document.parse(vista.getjTextArea1().getText()); col.insertOne(d); carregarDocuments(); } //Borrar documents if (actionEvent.getSource().equals(vista.getjButton3())) { MongoCollection col = model.getMongoClient().getDatabase(vistaDB.getjList1().getSelectedValue()) .getCollection(vista.getjList1().getSelectedValue()); Document doc = vista.getjList2().getSelectedValue(); System.out.println(doc.get("_id.timestamp")); ObjectId id = (ObjectId) doc.get("_id"); col.deleteOne(eq("_id", new ObjectId(id.toString()))); carregarDocuments(); } //Canviar de database if (actionEvent.getSource().equals(vista.getjButton7())) { vista.setVisible(false); vistaDB.setVisible(true); carregarKeysCombo(); } if (actionEvent.getSource().equals(vista.getjButton5())) { try { MongoCollection col = model.getMongoClient() .getDatabase(vistaDB.getjList1().getSelectedValue()) .getCollection(vista.getjList1().getSelectedValue()); Document d = vista.getjList2().getSelectedValue(); String key = vista.getjComboBox2().getSelectedItem().toString(); String value = d.get(key).toString(); String newKey = vista.getjTextField1().getText(); UpdateResult resultat = col.updateOne(eq(key, value), unset(newKey)); carregarDocuments(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Selecciona un document que modificar"); } } if (actionEvent.getSource().equals(vista.getjButton4())) { try { MongoCollection col = model.getMongoClient() .getDatabase(vistaDB.getjList1().getSelectedValue()) .getCollection(vista.getjList1().getSelectedValue()); Document d = vista.getjList2().getSelectedValue(); String key = vista.getjComboBox2().getSelectedItem().toString(); String value = d.get(key).toString(); String newKey = vista.getjTextField1().getText(); String newValue = vista.getjTextArea2().getText(); if (vista.getjTextField1().getText().equals("")) { UpdateResult resultat = col.updateOne(eq(key, value), set(key, newValue)); } else if (!vista.getjTextField1().getText().equals("")) { UpdateResult resultat = col.updateOne(eq(key, value), set(newKey, newValue)); } carregarDocuments(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Selecciona un document que modificar"); } } } }; vista.getjButton6().addActionListener(actionListener); vistaDB.getjButton2().addActionListener(actionListener); vistaDB.getjButton1().addActionListener(actionListener); vista.getjButton1().addActionListener(actionListener); vista.getjButton7().addActionListener(actionListener); vista.getjButton2().addActionListener(actionListener); vista.getjButton3().addActionListener(actionListener); vista.getjButton5().addActionListener(actionListener); vista.getjButton4().addActionListener(actionListener); MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getSource().equals(vista.getjList2())) { try { filasel = vista.getjList2().getSelectedIndex(); if (filasel != -1) { carregarDocumentsGson(); carregarKeysCombo(); } } catch (NumberFormatException ex) { } } if (e.getSource().equals(vista.getjList1())) { try { filasel = vista.getjList1().getSelectedIndex(); if (filasel != -1) { carregarDocuments(); } } catch (NumberFormatException ex) { } } } }; vista.getjList2().addMouseListener(mouseAdapter); vista.getjList1().addMouseListener(mouseAdapter); }