/** * Creates an index on the field specified, if that index does not already exist. * * <p>Prior to MongoDB 3.0 the dropDups option could be used with unique indexes allowing documents with duplicate values to be dropped * when building the index. Later versions of MongoDB will silently ignore this setting. </p> * * @param keys a document that contains pairs with the name of the field or fields to index and order of the index * @param options a document that controls the creation of the index. * @mongodb.driver.manual /administration/indexes-creation/ Index Creation Tutorials */ public void createIndex(final DBObject keys, final DBObject options) { try { executor.execute(createIndexOperation(keys, options), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * Drops (deletes) this collection from the database. Use with care. * * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/drop/ Drop Command */ public void drop() { try { executor.execute(new DropCollectionOperation(getNamespace(), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * 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 the index with the given name from this collection. * * @param indexName name of index to drop * @throws MongoException if the index does not exist * @mongodb.driver.manual core/indexes/ Indexes */ public void dropIndex(final String indexName) { try { executor.execute(new DropIndexOperation(getNamespace(), indexName, getWriteConcern()), getReadConcern()); } 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); } }
/** * Drops an index from this collection. The DBObject index parameter must match the specification of the index to drop, i.e. correct * key name and type must be specified. * * @param index the specification of the index to drop * @throws MongoException if the index does not exist * @mongodb.driver.manual core/indexes/ Indexes */ public void dropIndex(final DBObject index) { try { executor.execute(new DropIndexOperation(getNamespace(), wrap(index), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
executor.execute(getCreateCollectionOperation(collectionName, options), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e);
/** * 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); } }
/** * Change the name of an existing collection. * * @param newName specifies the new name of the collection * @param dropTarget If {@code true}, mongod will drop the collection with the target name if it exists * @return the collection with new name * @throws MongoException if target is the name of an existing collection and {@code dropTarget=false}. * @mongodb.driver.manual reference/command/renameCollection/ Rename Collection */ public DBCollection rename(final String newName, final boolean dropTarget) { try { executor.execute(new RenameCollectionOperation(getNamespace(), new MongoNamespace(getNamespace().getDatabaseName(), newName), getWriteConcern()) .dropTarget(dropTarget), getReadConcern()); return getDB().getCollection(newName); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
return executor.execute(operation, getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e);
return new MapReduceOutput(command.toDBObject(), executionResult, mapReduceStatistics, mapReduceOutputCollection); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e);
/** * Creates an index on the field specified, if that index does not already exist. * * <p>Prior to MongoDB 3.0 the dropDups option could be used with unique indexes allowing documents with duplicate values to be dropped * when building the index. Later versions of MongoDB will silently ignore this setting. </p> * * @param keys a document that contains pairs with the name of the field or fields to index and order of the index * @param options a document that controls the creation of the index. * @mongodb.driver.manual /administration/indexes-creation/ Index Creation Tutorials */ public void createIndex(final DBObject keys, final DBObject options) { try { executor.execute(createIndexOperation(keys, options), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * Drops (deletes) this collection from the database. Use with care. * * @throws MongoException if the operation failed * @mongodb.driver.manual reference/command/drop/ Drop Command */ public void drop() { try { executor.execute(new DropCollectionOperation(getNamespace(), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * Drops the index with the given name from this collection. * * @param indexName name of index to drop * @throws MongoException if the index does not exist * @mongodb.driver.manual core/indexes/ Indexes */ public void dropIndex(final String indexName) { try { executor.execute(new DropIndexOperation(getNamespace(), indexName, getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * 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); } }
/** * Drops an index from this collection. The DBObject index parameter must match the specification of the index to drop, i.e. correct * key name and type must be specified. * * @param index the specification of the index to drop * @throws MongoException if the index does not exist * @mongodb.driver.manual core/indexes/ Indexes */ public void dropIndex(final DBObject index) { try { executor.execute(new DropIndexOperation(getNamespace(), wrap(index), getWriteConcern()), getReadConcern()); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }
/** * Change the name of an existing collection. * * @param newName specifies the new name of the collection * @param dropTarget If {@code true}, mongod will drop the collection with the target name if it exists * @return the collection with new name * @throws MongoException if target is the name of an existing collection and {@code dropTarget=false}. * @mongodb.driver.manual reference/command/renameCollection/ Rename Collection */ public DBCollection rename(final String newName, final boolean dropTarget) { try { executor.execute(new RenameCollectionOperation(getNamespace(), new MongoNamespace(getNamespace().getDatabaseName(), newName), getWriteConcern()) .dropTarget(dropTarget), getReadConcern()); return getDB().getCollection(newName); } catch (MongoWriteConcernException e) { throw createWriteConcernException(e); } }