예제 #1
0
 CommandResult executeCommand(
     final BsonDocument commandDocument, final ReadPreference readPreference) {
   return new CommandResult(
       executor.execute(
           new CommandReadOperation<BsonDocument>(
               getName(), commandDocument, new BsonDocumentCodec()),
           readPreference));
 }
예제 #2
0
 /**
  * Adds or updates a user for this database
  *
  * @param userName the user name
  * @param password the password
  * @param readOnly if true, user will only be able to read
  * @return the result of executing this operation
  * @throws MongoException if the operation failed
  * @mongodb.driver.manual administration/security-access-control/ Access Control
  * @mongodb.driver.manual reference/command/createUser createUser
  * @mongodb.driver.manual reference/command/updateUser updateUser
  * @deprecated Use {@code DB.command} to call either the createUser or updateUser command
  */
 @Deprecated
 public WriteResult addUser(final String userName, final char[] password, final boolean readOnly) {
   MongoCredential credential = createMongoCRCredential(userName, getName(), password);
   boolean userExists = false;
   try {
     userExists = executor.execute(new UserExistsOperation(getName(), userName), primary());
   } catch (MongoCommandException e) {
     if (e.getCode() != 13) {
       throw e;
     }
   }
   if (userExists) {
     executor.execute(new UpdateUserOperation(credential, readOnly));
     return new WriteResult(1, true, null);
   } else {
     executor.execute(new CreateUserOperation(credential, readOnly));
     return new WriteResult(1, false, null);
   }
 }
예제 #3
0
 CommandResult executeCommand(final BsonDocument commandDocument) {
   return new CommandResult(
       executor.execute(
           new CommandWriteOperation<BsonDocument>(
               getName(), commandDocument, new BsonDocumentCodec())));
 }
예제 #4
0
 /**
  * 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) {
   executor.execute(new DropUserOperation(getName(), userName));
   return new WriteResult(1, true, null);
 }
예제 #5
0
 /**
  * Creates a collection with a given name and options. If the collection already exists, this
  * throws a {@code CommandFailureException}.
  *
  * <p>Possible options:
  *
  * <ul>
  *   <li><b>capped</b> ({@code boolean}) - Enables a collection cap. False by default. If enabled,
  *       you must specify a size parameter.
  *   <li><b>size</b> ({@code int}) - If capped is true, size specifies a maximum size in bytes for
  *       the capped collection. When capped is false, you may use size to preallocate space.
  *   <li><b>max</b> ({@code int}) - Optional. Specifies a maximum "cap" in number of documents for
  *       capped collections. You must also specify size when specifying max.
  * </ul>
  *
  * <p>Note that if the {@code options} parameter is {@code null}, the creation will be deferred to
  * when the collection is written to.
  *
  * @param collectionName the name of the collection to return
  * @param options options
  * @return the collection
  * @throws MongoException if there's a failure
  * @mongodb.driver.manual reference/method/db.createCollection/ createCollection()
  */
 public DBCollection createCollection(final String collectionName, final DBObject options) {
   if (options != null) {
     executor.execute(getCreateCollectionOperation(collectionName, options));
   }
   return getCollection(collectionName);
 }