@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(ClientSession clientSession,
java.lang.String collectionName)
Create a new collection with the given name.
|
void |
createCollection(ClientSession clientSession,
java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a new collection with the selected options
|
void |
createCollection(java.lang.String collectionName)
Create a new collection with the given name.
|
void |
createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a new collection with the selected options
|
void |
createView(ClientSession clientSession,
java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
createView(ClientSession clientSession,
java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
drop()
Drops this database.
|
void |
drop(ClientSession clientSession)
Drops this database.
|
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoDatabase.
|
MongoCollection<Document> |
getCollection(java.lang.String collectionName)
Gets a collection.
|
<TDocument> |
getCollection(java.lang.String collectionName,
java.lang.Class<TDocument> documentClass)
Gets a collection, with a specific default document class.
|
java.lang.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<java.lang.String> |
listCollectionNames()
Gets the names of all the collections in this database.
|
MongoIterable<java.lang.String> |
listCollectionNames(ClientSession clientSession)
Gets the names of all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections()
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(java.lang.Class<TResult> resultClass)
Finds all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections(ClientSession clientSession)
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(ClientSession clientSession,
java.lang.Class<TResult> resultClass)
Finds all the collections in this database.
|
Document |
runCommand(Bson command)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
<TResult> TResult |
runCommand(Bson command,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
Document |
runCommand(Bson command,
ReadPreference readPreference)
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(Bson command,
ReadPreference readPreference,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with the given read preference.
|
Document |
runCommand(ClientSession clientSession,
Bson command)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
<TResult> TResult |
runCommand(ClientSession clientSession,
Bson command,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary() . |
Document |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference)
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with the given read preference.
|
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.
|
java.lang.String getName()
CodecRegistry getCodecRegistry()
CodecRegistry
ReadPreference getReadPreference()
ReadPreference
WriteConcern getWriteConcern()
WriteConcern
ReadConcern getReadConcern()
ReadConcern
MongoDatabase 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(java.lang.String collectionName)
collectionName
- the name of the collection to returnjava.lang.IllegalArgumentException
- if collectionName is invalidMongoNamespace.checkCollectionNameValidity(String)
<TDocument> MongoCollection<TDocument> getCollection(java.lang.String collectionName, java.lang.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.Document runCommand(Bson command)
ReadPreference.primary()
.command
- the command to be runDocument runCommand(Bson command, ReadPreference readPreference)
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the command<TResult> TResult runCommand(Bson command, java.lang.Class<TResult> resultClass)
ReadPreference.primary()
.TResult
- the type of the class to use instead of Document
.command
- the command to be runresultClass
- the class to decode each document into<TResult> TResult runCommand(Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
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 class to decode each document intoDocument runCommand(ClientSession clientSession, Bson command)
ReadPreference.primary()
.clientSession
- the client session with which to associate this operationcommand
- the command to be runDocument runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference)
clientSession
- the client session with which to associate this operationcommand
- the command to be runreadPreference
- the ReadPreference
to be used when executing the command<TResult> TResult runCommand(ClientSession clientSession, Bson command, java.lang.Class<TResult> resultClass)
ReadPreference.primary()
.TResult
- the type of the class to use instead of Document
.clientSession
- the client session with which to associate this operationcommand
- the command to be runresultClass
- the class to decode each document into<TResult> TResult runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
TResult
- the type of the class to use instead of Document
.clientSession
- the client session with which to associate this operationcommand
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandresultClass
- the class to decode each document intovoid drop()
void drop(ClientSession clientSession)
clientSession
- the client session with which to associate this operationMongoIterable<java.lang.String> listCollectionNames()
ListCollectionsIterable<Document> listCollections()
<TResult> ListCollectionsIterable<TResult> listCollections(java.lang.Class<TResult> resultClass)
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intoMongoIterable<java.lang.String> listCollectionNames(ClientSession clientSession)
clientSession
- the client session with which to associate this operationListCollectionsIterable<Document> listCollections(ClientSession clientSession)
clientSession
- the client session with which to associate this operation<TResult> ListCollectionsIterable<TResult> listCollections(ClientSession clientSession, java.lang.Class<TResult> resultClass)
TResult
- the target document type of the iterable.clientSession
- the client session with which to associate this operationresultClass
- the class to decode each document intovoid createCollection(java.lang.String collectionName)
collectionName
- the name for the new collection to createvoid createCollection(java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
collectionName
- the name for the new collection to createcreateCollectionOptions
- various options for creating the collectionvoid createCollection(ClientSession clientSession, java.lang.String collectionName)
clientSession
- the client session with which to associate this operationcollectionName
- the name for the new collection to createvoid createCollection(ClientSession clientSession, java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
clientSession
- the client session with which to associate this operationcollectionName
- the name for the new collection to createcreateCollectionOptions
- various options for creating the collectionvoid createView(java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline)
viewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewvoid createView(java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
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 viewvoid createView(ClientSession clientSession, java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline)
clientSession
- the client session with which to associate this operationviewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewvoid createView(ClientSession clientSession, java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
clientSession
- the client session with which to associate this operationviewName
- 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 view