@ThreadSafe public interface MongoDatabase
Note: Additions to this interface will not be considered to break binary compatibility.
| Modifier and Type | Method and Description |
|---|---|
void |
createCollection(String collectionName,
CreateCollectionOptions options,
SingleResultCallback<Void> callback)
Create a new collection with the selected options
|
void |
createCollection(String collectionName,
SingleResultCallback<Void> callback)
Create a new collection with the given name.
|
void |
createView(String viewName,
String viewOn,
List<? extends Bson> pipeline,
CreateViewOptions createViewOptions,
SingleResultCallback<Void> callback)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
createView(String viewName,
String viewOn,
List<? extends Bson> pipeline,
SingleResultCallback<Void> callback)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
drop(SingleResultCallback<Void> callback)
Drops this database.
|
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoDatabase.
|
MongoCollection<Document> |
getCollection(String collectionName)
Gets a collection.
|
<TDocument> |
getCollection(String collectionName,
Class<TDocument> documentClass)
Gets a collection, with a specific default document class.
|
String |
getName()
Gets the name of the database.
|
ReadConcern |
getReadConcern()
Get the read concern for the MongoDatabase.
|
ReadPreference |
getReadPreference()
Get the read preference for the MongoDatabase.
|
WriteConcern |
getWriteConcern()
Get the write concern for the MongoDatabase.
|
MongoIterable<String> |
listCollectionNames()
Gets the names of all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections()
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(Class<TResult> resultClass)
Finds all the collections in this database.
|
<TResult> void |
runCommand(Bson command,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
<TResult> void |
runCommand(Bson command,
ReadPreference readPreference,
Class<TResult> resultClass,
SingleResultCallback<TResult> callback)
Executes the given command in the context of the current database with the given read preference.
|
void |
runCommand(Bson command,
ReadPreference readPreference,
SingleResultCallback<Document> callback)
Executes the given command in the context of the current database with the given read preference.
|
void |
runCommand(Bson command,
SingleResultCallback<Document> callback)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
MongoDatabase |
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoDatabase instance with a different codec registry.
|
MongoDatabase |
withReadConcern(ReadConcern readConcern)
Create a new MongoDatabase instance with a different read concern.
|
MongoDatabase |
withReadPreference(ReadPreference readPreference)
Create a new MongoDatabase instance with a different read preference.
|
MongoDatabase |
withWriteConcern(WriteConcern writeConcern)
Create a new MongoDatabase instance with a different write concern.
|
String getName()
CodecRegistry getCodecRegistry()
CodecRegistryReadPreference getReadPreference()
ReadPreferenceWriteConcern getWriteConcern()
WriteConcernReadConcern getReadConcern()
ReadConcernMongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
codecRegistry - the new CodecRegistry for the databaseMongoDatabase withReadPreference(ReadPreference readPreference)
readPreference - the new ReadPreference for the databaseMongoDatabase withWriteConcern(WriteConcern writeConcern)
writeConcern - the new WriteConcern for the databaseMongoDatabase withReadConcern(ReadConcern readConcern)
readConcern - the new ReadConcern for the databaseMongoCollection<Document> getCollection(String collectionName)
collectionName - the name of the collection to returnIllegalArgumentException - if collectionName is invalidMongoNamespace.checkCollectionNameValidity(String)<TDocument> MongoCollection<TDocument> getCollection(String collectionName, Class<TDocument> documentClass)
TDocument - the type of the class to use instead of Document.collectionName - the name of the collection to returndocumentClass - the default class to cast any documents returned from the database into.void runCommand(Bson command, SingleResultCallback<Document> callback)
ReadPreference.primary().command - the command to be runcallback - the callback that is passed the command resultvoid runCommand(Bson command, ReadPreference readPreference, SingleResultCallback<Document> callback)
command - the command to be runreadPreference - the ReadPreference to be used when executing the commandcallback - the callback that is passed the command result<TResult> void runCommand(Bson command, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
ReadPreference.primary().TResult - the type of the class to use instead of Document.command - the command to be runresultClass - the default class to cast any documents returned from the database into.callback - the callback that is passed the command result<TResult> void runCommand(Bson command, ReadPreference readPreference, Class<TResult> resultClass, SingleResultCallback<TResult> callback)
TResult - the type of the class to use instead of Document.command - the command to be runreadPreference - the ReadPreference to be used when executing the commandresultClass - the default class to cast any documents returned from the database into.callback - the callback that is passed the command resultvoid drop(SingleResultCallback<Void> callback)
callback - the callback that is completed once the database has been droppedMongoIterable<String> listCollectionNames()
ListCollectionsIterable<Document> listCollections()
<TResult> ListCollectionsIterable<TResult> listCollections(Class<TResult> resultClass)
TResult - the target document type of the iterable.resultClass - the class to decode each document intovoid createCollection(String collectionName, SingleResultCallback<Void> callback)
collectionName - the name for the new collection to createcallback - the callback that is completed once the collection has been createdvoid createCollection(String collectionName, CreateCollectionOptions options, SingleResultCallback<Void> callback)
collectionName - the name for the new collection to createoptions - various options for creating the collectioncallback - the callback that is completed once the collection has been createdvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline, SingleResultCallback<Void> callback)
viewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewcallback - the callback that is completed once the collection has been createdvoid createView(String viewName, String viewOn, List<? extends Bson> pipeline, CreateViewOptions createViewOptions, SingleResultCallback<Void> callback)
viewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewcreateViewOptions - various options for creating the viewcallback - the callback that is completed once the collection has been created