List of usage examples for com.mongodb.client.result DeleteResult wasAcknowledged
public abstract boolean wasAcknowledged();
From source file:com.dydabo.blackbox.mongodb.tasks.MongoDeleteTask.java
License:Apache License
/** * @param row/*w ww . ja v a 2 s . c o m*/ * @return */ private Boolean delete(T row) { Document doc = utils.parseRowToDocument(row); DeleteResult delResult = collection .deleteOne(Filters.eq(MongoUtils.PRIMARYKEY, doc.get(MongoUtils.PRIMARYKEY))); return delResult.wasAcknowledged(); }
From source file:com.yahoo.ycsb.db3.MongoDbClient.java
License:Open Source License
/** * Delete a record from the database.// w w w . j a v a 2 s . c o m * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See the {@link DB} * class's description for a discussion of error codes. */ @Override public Status delete(String table, String key) { try { MongoCollection<Document> collection = database.getCollection(table); Document query = new Document("_id", key); DeleteResult result = collection.withWriteConcern(writeConcern).deleteOne(query); if (result.wasAcknowledged() && result.getDeletedCount() == 0) { System.err.println("Nothing deleted for key " + key); return Status.NOT_FOUND; } return Status.OK; } catch (Exception e) { System.err.println(e.toString()); return Status.ERROR; } }
From source file:eu.operando.core.pdb.mongo.OSPPrivacyPolicyMongo.java
/** * * @param ospId/*from w ww. jav a 2 s. c o m*/ * @return */ public boolean deleteOSPById(String ospId) { boolean ret = false; try { Bson filter = new Document("_id", new ObjectId(ospId)); DeleteResult result = ospCollection.deleteOne(filter); ret = result.wasAcknowledged(); } catch (MongoWriteException ex) { ex.printStackTrace(); } catch (MongoWriteConcernException ex) { ex.printStackTrace(); } catch (MongoException ex) { ex.printStackTrace(); } return ret; }
From source file:eu.operando.core.pdb.mongo.RegulationsMongo.java
/** * * @param regId//from ww w. j av a2s . c o m * @return */ public boolean deleteRegulationById(String regId) { boolean ret = false; try { Bson filter = new Document("_id", new ObjectId(regId)); DeleteResult result = regCollection.deleteOne(filter); ret = result.wasAcknowledged(); } catch (MongoWriteException ex) { ex.printStackTrace(); } catch (MongoWriteConcernException ex) { ex.printStackTrace(); } catch (MongoException ex) { ex.printStackTrace(); } return ret; }
From source file:eu.operando.core.pdb.mongo.UPPMongo.java
/** * * @param ospId/*from w w w .j ava2s .c o m*/ * @return */ public boolean deleteUPPById(String uppId) { System.out.println("deleting: " + uppId); boolean ret = false; try { Bson filter = new Document("userId", uppId); DeleteResult result = uppCollection.deleteOne(filter); ret = result.wasAcknowledged(); } catch (MongoWriteException ex) { ex.printStackTrace(); } catch (MongoWriteConcernException ex) { ex.printStackTrace(); } catch (MongoException ex) { ex.printStackTrace(); } return ret; }
From source file:eu.vital.vitalcep.restApp.vuaippi.Observation.java
@POST @Path("stream/unsubscribe") @Consumes(MediaType.APPLICATION_JSON)//from www . ja va2s . c o m @Produces(MediaType.APPLICATION_JSON) public Response unSubscribeToObservations(String info, @Context HttpServletRequest req) throws FileNotFoundException, IOException { JSONObject jObject = new JSONObject(); try { jObject = new JSONObject(info); if (!jObject.has("subscription")) { return Response.status(Response.Status.BAD_REQUEST).build(); } } catch (Exception e) { return Response.status(Response.Status.BAD_REQUEST).build(); } StringBuilder ck = new StringBuilder(); Security slogin = new Security(); Boolean token = slogin.login(req.getHeader("name"), req.getHeader("password"), false, ck); if (!token) { return Response.status(Response.Status.UNAUTHORIZED).build(); } MongoClient mongo = new MongoClient(new MongoClientURI(mongoURL)); MongoDatabase db = mongo.getDatabase(mongoDB); Document doc = new Document("_id", new ObjectId(jObject.getString("subscription"))); DeleteResult deleted = db.getCollection("subscriptions").deleteOne(doc); db = null; if (mongo != null) { mongo.close(); mongo = null; } if (deleted.wasAcknowledged() != true || deleted.getDeletedCount() != 1) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.status(Response.Status.OK).build(); }
From source file:org.nuxeo.directory.mongodb.MongoDBReference.java
License:Apache License
private void removeLinksFor(String field, String value, MongoDBSession session) { try {//from w w w . j a v a 2 s .c o m DeleteResult result = session.getCollection(collection) .deleteMany(MongoDBSerializationHelper.fieldMapToBson(field, value)); if (!result.wasAcknowledged()) { throw new DirectoryException( "Error while deleting the entry, the request has not been acknowledged by the server"); } } catch (MongoWriteException e) { throw new DirectoryException(e); } }
From source file:org.nuxeo.directory.mongodb.MongoDBSession.java
License:Apache License
@Override public void deleteEntry(String id) throws DirectoryException { checkPermission(SecurityConstants.WRITE); checkDeleteConstraints(id);/*from www. j av a 2 s. c o m*/ for (Reference reference : getDirectory().getReferences()) { if (reference instanceof MongoDBReference) { MongoDBReference mongoDBReference = (MongoDBReference) reference; mongoDBReference.removeLinksForSource(id, this); } else { reference.removeLinksForSource(id); } } try { DeleteResult result = getCollection() .deleteOne(MongoDBSerializationHelper.fieldMapToBson(getIdField(), id)); if (!result.wasAcknowledged()) { throw new DirectoryException( "Error while deleting the entry, the request has not been acknowledged by the server"); } } catch (MongoWriteException e) { throw new DirectoryException(e); } getDirectory().invalidateCaches(); }