/** * Gets an instance representing an unacknowledged write. * * @return an instance representing an unacknowledged write * @since 3.0 */ public static WriteResult unacknowledged() { return new WriteResult(); }
/** * Removes the specified user from the database. * * @param userName user to be removed * @return the result of executing this operation * @throws MongoException if the operation failed * @mongodb.driver.manual administration/security-access-control/ Access Control * @deprecated Use {@code DB.command} to call the dropUser command */ @Deprecated public WriteResult removeUser(final String userName) { try { executor.execute(new com.mongodb.operation.DropUserOperation(getName(), userName, getWriteConcern()), getReadConcern()); return new WriteResult(1, true, null); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
private WriteResult translateWriteResult(final int count, final boolean isUpdateOfExisting, @Nullable final BsonValue upsertedId) { Object newUpsertedId = upsertedId == null ? null : getObjectCodec().decode(new BsonDocumentReader(new BsonDocument("_id", upsertedId)), DecoderContext.builder().build()) .get("_id"); return new WriteResult(count, isUpdateOfExisting, newUpsertedId); }
if (userExists) { executor.execute(new com.mongodb.operation.UpdateUserOperation(credential, readOnly, getWriteConcern()), getReadConcern()); return new WriteResult(1, true, null); } else { executor.execute(new com.mongodb.operation.CreateUserOperation(credential, readOnly, getWriteConcern()), getReadConcern()); return new WriteResult(1, false, null);
/** * Gets an instance representing an unacknowledged write. * * @return an instance representing an unacknowledged write * @since 3.0 */ public static WriteResult unacknowledged() { return new WriteResult(); }
@Override public synchronized WriteResult remove(DBObject o, WriteConcern concern, DBEncoder encoder) throws MongoException { o = filterLists(o); if (LOG.isDebugEnabled()) { LOG.debug("remove: " + o); } int updatedDocuments = 0; Collection<DBObject> objectsByIndex = filterByIndexes(o); Filter filter = expressionParser.buildFilter(o); List<DBObject> ids = new ArrayList<DBObject>(); // Double pass, objectsByIndex can be not "objects" for (DBObject object : objectsByIndex) { if (filter.apply(object)) { ids.add(object); } } // Real remove. for (DBObject object : ids) { LOG.debug("remove object : {}", object); removeFromIndexes(object); updatedDocuments++; } return new WriteResult(updateResult(updatedDocuments, false), concern); }
@Override public synchronized WriteResult insert(List<DBObject> toInsert, WriteConcern concern, DBEncoder encoder) { for (DBObject obj : toInsert) { DBObject cloned = filterLists(Util.cloneIdFirst(obj)); if (LOG.isDebugEnabled()) { LOG.debug("insert: " + cloned); } ObjectId id = putIdIfNotPresent(cloned); if (!(obj instanceof LazyDBObject) && obj.get(ID_KEY) == null) { obj.put(ID_KEY, id); } putSizeCheck(cloned, concern); } return new WriteResult(insertResult(toInsert.size()), concern); }
/** * Removes the specified user from the database. * * @param userName user to be removed * @return the result of executing this operation * @throws MongoException if the operation failed * @mongodb.driver.manual administration/security-access-control/ Access Control * @deprecated Use {@code DB.command} to call the dropUser command */ @Deprecated public WriteResult removeUser(final String userName) { try { executor.execute(new com.mongodb.operation.DropUserOperation(getName(), userName, getWriteConcern()), getReadConcern()); return new WriteResult(1, true, null); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
private WriteResult translateWriteResult(final int count, final boolean isUpdateOfExisting, @Nullable final BsonValue upsertedId) { Object newUpsertedId = upsertedId == null ? null : getObjectCodec().decode(new BsonDocumentReader(new BsonDocument("_id", upsertedId)), DecoderContext.builder().build()) .get("_id"); return new WriteResult(count, isUpdateOfExisting, newUpsertedId); }
if (userExists) { executor.execute(new com.mongodb.operation.UpdateUserOperation(credential, readOnly, getWriteConcern()), getReadConcern()); return new WriteResult(1, true, null); } else { executor.execute(new com.mongodb.operation.CreateUserOperation(credential, readOnly, getWriteConcern()), getReadConcern()); return new WriteResult(1, false, null);
return new WriteResult(updateResult(updatedDocuments, updatedExisting), concern);