List of usage examples for com.mongodb.client.result UpdateResult getModifiedCount
public abstract long getModifiedCount();
From source file:BlogPostDAO.java
License:Apache License
public void addPostComment(final String name, final String email, final String body, final String permalink) { Document comment = new Document("author", name).append("body", body); if (email != null && !email.equals("")) { comment.append("email", email); }/*from w w w .j a va 2 s . co m*/ UpdateResult result = postsCollection.updateOne(new Document("permalink", permalink), new Document("$push", new Document("comments", comment))); logger.info("Matches: " + result.getMatchedCount()); logger.info("Modified: " + result.getModifiedCount()); }
From source file:anuncius.singleton.MongoHandler.java
public boolean delete(int id, String collectionName) { MongoCollection<Document> collection = mainDatabase.getCollection(collectionName); Document document = new Document(); document.put("_id", id); document.put("deleted", true); UpdateResult result = collection.updateOne(document, document); return result.getModifiedCount() >= 1; }
From source file:com.amertkara.tinkerpop.blueprints.impl.mongodb.MongoDBElement.java
License:Apache License
@Override public void setProperty(final String key, final Object value) { ElementHelper.validateProperty(this, key, value); UpdateResult result = getMongoCollection().updateOne(this.rawElement, new Document("$set", new Document(MongoDBConstants.FIELD_PROPERTIES, new Document(key, value)))); if (result.getMatchedCount() == result.getModifiedCount()) { logger.info("Property of element " + this.rawElement.get(MongoDBConstants.FIELD_ID) + " is set."); }/*from ww w.j a v a2 s . c om*/ // Refresh the rawElement this.reload(); }
From source file:com.amertkara.tinkerpop.blueprints.impl.mongodb.MongoDBElement.java
License:Apache License
@Override public <T> T removeProperty(final String key) { if (getProperty(key) == null) { return null; } else {//from w w w .jav a 2s .co m UpdateResult result = getMongoCollection().updateOne(this.rawElement, new Document("$unset", new Document(MongoDBConstants.FIELD_PROPERTIES + "." + key, ""))); if (result.getMatchedCount() == result.getModifiedCount()) { logger.info("Property of element " + this.rawElement.get(MongoDBConstants.FIELD_ID) + " is unset."); } T removedProperty = this.getProperty(key); // Refresh the rawElement reload(); return removedProperty; } }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
private Integer update(T t2, Document doc) { Integer documentosModificados = 0; Document search = new Document(); try {//w ww .jav a 2s. com search = findDocPrimaryKey(t2); UpdateResult updateResult = getMongoDatabase().getCollection(collection).updateOne(search, doc); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "updateOne()").log(Level.SEVERE, null, e); exception = new Exception("updateOne() ", e); } return 0; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
public Integer update(Document docSearch, Document docUpdate) { Integer documentosModificados = 0; try {//from w ww.j av a 2 s .c o m UpdateResult updateResult = getMongoDatabase().getCollection(collection).updateOne(docSearch, docUpdate); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "updateOne()").log(Level.SEVERE, null, e); exception = new Exception("updateOne() ", e); } return 0; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * Actualiza multiples documentos/*w w w.j a v a 2 s . co m*/ * * @param docSearch * @param docUpdate * @return */ public Integer updateMany(Document docSearch, Document docUpdate) { Integer documentosModificados = 0; try { UpdateResult updateResult = getMongoDatabase().getCollection(collection).updateMany(docSearch, docUpdate); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "updateMany()").log(Level.SEVERE, null, e); exception = new Exception("updateMany() ", e); } return 0; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * implementa replaceOne/* w w w . j av a2 s.c om*/ * * @param key * @param value * @param docUpdate * @return */ public Integer replaceOne(String key, String value, Document docUpdate) { Integer documentosModificados = 0; try { UpdateResult updateResult = getMongoDatabase().getCollection(collection) .replaceOne(Filters.eq(key, value), docUpdate); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "replaceOne()").log(Level.SEVERE, null, e); exception = new Exception("replaceOne() ", e); } return 0; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param key/*w ww.j a v a 2s.c om*/ * @param value * @param docUpdate * @return */ public Integer replaceOne(Bson search, Document docUpdate) { Integer documentosModificados = 0; try { UpdateResult updateResult = getMongoDatabase().getCollection(collection).replaceOne(search, docUpdate); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "replaceOne()").log(Level.SEVERE, null, e); exception = new Exception("replaceOne() ", e); } return 0; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param docSearch//from w w w . j a va 2 s .co m * @param docUpdate * @param options * @return */ public Integer replaceOne(Document docSearch, Document docUpdate, String... options) { Integer documentosModificados = 0; try { UpdateResult updateResult = getMongoDatabase().getCollection(collection).replaceOne(docSearch, docUpdate); return (int) updateResult.getModifiedCount(); } catch (Exception e) { Logger.getLogger(Repository.class.getName() + "updateOne()").log(Level.SEVERE, null, e); exception = new Exception("updateOne() ", e); } return 0; }