/** * Get the read concern for this collection. * * @return the {@link com.mongodb.ReadConcern} * @since 3.3 * @mongodb.server.release 3.2 * @mongodb.driver.manual reference/readConcern/ Read Concern */ public ReadConcern getReadConcern() { if (readConcern != null) { return readConcern; } return database.getReadConcern(); }
/** * 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); } }
/** * Drops this database. Removes all data on disk. Use with caution. * * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/dropDatabase/ Drop Database */ public void dropDatabase() { try { getExecutor().execute(new DropDatabaseOperation(getName(), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
if (options != null) { try { executor.execute(getCreateCollectionOperation(collectionName, options), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e);
CommandResult executeCommand(final BsonDocument commandDocument, final ReadPreference readPreference) { return new CommandResult(executor.execute(new CommandReadOperation<BsonDocument>(getName(), commandDocument, new BsonDocumentCodec()), readPreference, getReadConcern())); }
boolean userExists = false; try { userExists = executor.execute(new com.mongodb.operation.UserExistsOperation(getName(), userName), primary(), getReadConcern()); } catch (MongoCommandException e) { if (e.getCode() != 13) { 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);
CommandResult executeCommand(final BsonDocument commandDocument) { return new CommandResult(executor.execute(new CommandWriteOperation<BsonDocument>(getName(), commandDocument, new BsonDocumentCodec()), getReadConcern())); }
/** * Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view. * * @param viewName the name of the view to create * @param viewOn the backing collection/view for the view * @param pipeline the pipeline that defines the view * @param options the options for creating the view * @return the view as a DBCollection * @throws MongoCommandException if the server is unable to create the collection * @throws WriteConcernException if the {@code WriteConcern} specified on this {@code DB} could not be satisfied * @throws MongoException for all other failures * @since 3.4 * @mongodb.server.release 3.4 * @mongodb.driver.manual reference/command/create Create Command */ public DBCollection createView(final String viewName, final String viewOn, final List<? extends DBObject> pipeline, final DBCreateViewOptions options) { try { notNull("options", options); DBCollection view = getCollection(viewName); executor.execute(new CreateViewOperation(name, viewName, viewOn, view.preparePipeline(pipeline), writeConcern) .collation(options.getCollation()), getReadConcern()); return view; } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * Get the read concern for this collection. * * @return the {@link com.mongodb.ReadConcern} * @since 3.3 * @mongodb.server.release 3.2 * @mongodb.driver.manual reference/readConcern/ Read Concern */ public ReadConcern getReadConcern() { if (readConcern != null) { return readConcern; } return database.getReadConcern(); }
/** * 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); } }
/** * Drops this database. Removes all data on disk. Use with caution. * * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/dropDatabase/ Drop Database */ public void dropDatabase() { try { getExecutor().execute(new DropDatabaseOperation(getName(), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
boolean userExists = false; try { userExists = executor.execute(new com.mongodb.operation.UserExistsOperation(getName(), userName), primary(), getReadConcern()); } catch (MongoCommandException e) { if (e.getCode() != 13) { 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);
CommandResult executeCommand(final BsonDocument commandDocument, final ReadPreference readPreference) { return new CommandResult(executor.execute(new CommandReadOperation<BsonDocument>(getName(), commandDocument, new BsonDocumentCodec()), readPreference, getReadConcern())); }
if (options != null) { try { executor.execute(getCreateCollectionOperation(collectionName, options), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e);
CommandResult executeCommand(final BsonDocument commandDocument) { return new CommandResult(executor.execute(new CommandWriteOperation<BsonDocument>(getName(), commandDocument, new BsonDocumentCodec()), getReadConcern())); }
/** * Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view. * * @param viewName the name of the view to create * @param viewOn the backing collection/view for the view * @param pipeline the pipeline that defines the view * @param options the options for creating the view * @return the view as a DBCollection * @throws MongoCommandException if the server is unable to create the collection * @throws WriteConcernException if the {@code WriteConcern} specified on this {@code DB} could not be satisfied * @throws MongoException for all other failures * @since 3.4 * @mongodb.server.release 3.4 * @mongodb.driver.manual reference/command/create Create Command */ public DBCollection createView(final String viewName, final String viewOn, final List<? extends DBObject> pipeline, final DBCreateViewOptions options) { try { notNull("options", options); DBCollection view = getCollection(viewName); executor.execute(new CreateViewOperation(name, viewName, viewOn, view.preparePipeline(pipeline), writeConcern) .collation(options.getCollation()), getReadConcern()); return view; } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }