All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mongodb.client.MongoDatabase Maven / Gradle / Ivy

Go to download

The MongoDB Java Driver uber-artifact, containing mongodb-driver, mongodb-driver-core, and bson

The newest version!
/*
 * Copyright (c) 2008-2014 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mongodb.client;

import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.annotations.ThreadSafe;
import com.mongodb.client.model.CreateCollectionOptions;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;

/**
 * The MongoDatabase interface.
 *
 * 

Note: Additions to this interface will not be considered to break binary compatibility.

* * @since 3.0 */ @ThreadSafe public interface MongoDatabase { /** * Gets the name of the database. * * @return the database name */ String getName(); /** * Get the codec registry for the MongoDatabase. * * @return the {@link org.bson.codecs.configuration.CodecRegistry} */ CodecRegistry getCodecRegistry(); /** * Get the read preference for the MongoDatabase. * * @return the {@link com.mongodb.ReadPreference} */ ReadPreference getReadPreference(); /** * Get the write concern for the MongoDatabase. * * @return the {@link com.mongodb.WriteConcern} */ WriteConcern getWriteConcern(); /** * Create a new MongoDatabase instance with a different codec registry. * * @param codecRegistry the new {@link org.bson.codecs.configuration.CodecRegistry} for the database * @return a new MongoDatabase instance with the different codec registry */ MongoDatabase withCodecRegistry(CodecRegistry codecRegistry); /** * Create a new MongoDatabase instance with a different read preference. * * @param readPreference the new {@link ReadPreference} for the database * @return a new MongoDatabase instance with the different readPreference */ MongoDatabase withReadPreference(ReadPreference readPreference); /** * Create a new MongoDatabase instance with a different write concern. * * @param writeConcern the new {@link WriteConcern} for the database * @return a new MongoDatabase instance with the different writeConcern */ MongoDatabase withWriteConcern(WriteConcern writeConcern); /** * Gets a collection. * * @param collectionName the name of the collection to return * @return the collection */ MongoCollection getCollection(String collectionName); /** * Gets a collection, with a specific default document class. * * @param collectionName the name of the collection to return * @param documentClass the default class to cast any documents returned from the database into. * @param the type of the class to use instead of {@code Document}. * @return the collection */ MongoCollection getCollection(String collectionName, Class documentClass); /** * Executes the given command in the context of the current database with a read preference of {@link ReadPreference#primary()}. * * @param command the command to be run * @return the command result */ Document runCommand(Bson command); /** * Executes the given command in the context of the current database with the given read preference. * * @param command the command to be run * @param readPreference the {@link ReadPreference} to be used when executing the command * @return the command result */ Document runCommand(Bson command, ReadPreference readPreference); /** * Executes the given command in the context of the current database with a read preference of {@link ReadPreference#primary()}. * * @param command the command to be run * @param resultClass the default class to cast any documents returned from the database into. * @param the type of the class to use instead of {@code Document}. * @return the command result */ TResult runCommand(Bson command, Class resultClass); /** * Executes the given command in the context of the current database with the given read preference. * * @param command the command to be run * @param readPreference the {@link ReadPreference} to be used when executing the command * @param resultClass the default class to cast any documents returned from the database into. * @param the type of the class to use instead of {@code Document}. * @return the command result */ TResult runCommand(Bson command, ReadPreference readPreference, Class resultClass); /** * Drops this database. * * @mongodb.driver.manual reference/commands/dropDatabase/#dbcmd.dropDatabase Drop database */ void drop(); /** * Gets the names of all the collections in this database. * * @return an iterable containing all the names of all the collections in this database */ MongoIterable listCollectionNames(); /** * Finds all the collections in this database. * * @return the list collections iterable interface * @mongodb.driver.manual reference/command/listCollections listCollections */ ListCollectionsIterable listCollections(); /** * Finds all the collections in this database. * * @param resultClass the class to decode each document into * @param the target document type of the iterable. * @return the list collections iterable interface * @mongodb.driver.manual reference/command/listCollections listCollections */ ListCollectionsIterable listCollections(Class resultClass); /** * Create a new collection with the given name. * * @param collectionName the name for the new collection to create * @mongodb.driver.manual reference/commands/create Create Command */ void createCollection(String collectionName); /** * Create a new collection with the selected options * * @param collectionName the name for the new collection to create * @param createCollectionOptions various options for creating the collection * @mongodb.driver.manual reference/commands/create Create Command */ void createCollection(String collectionName, CreateCollectionOptions createCollectionOptions); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy