class MongoDatabaseImpl extends java.lang.Object implements MongoDatabase
| Modifier and Type | Field and Description |
|---|---|
private CodecRegistry |
codecRegistry |
private AsyncOperationExecutor |
executor |
private java.lang.String |
name |
private ReadConcern |
readConcern |
private ReadPreference |
readPreference |
private WriteConcern |
writeConcern |
| Constructor and Description |
|---|
MongoDatabaseImpl(java.lang.String name,
CodecRegistry codecRegistry,
ReadPreference readPreference,
WriteConcern writeConcern,
ReadConcern readConcern,
AsyncOperationExecutor executor) |
| Modifier and Type | Method and Description |
|---|---|
private java.util.List<BsonDocument> |
createBsonDocumentList(java.util.List<? extends Bson> pipeline) |
void |
createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions,
SingleResultCallback<java.lang.Void> callback)
Create a new collection with the selected options
|
void |
createCollection(java.lang.String collectionName,
SingleResultCallback<java.lang.Void> callback)
Create a new collection with the given name.
|
void |
createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions,
SingleResultCallback<java.lang.Void> callback)
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,
SingleResultCallback<java.lang.Void> callback)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
drop(SingleResultCallback<java.lang.Void> callback)
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.
|
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.
|
<TResult> void |
runCommand(Bson command,
java.lang.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,
java.lang.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(). |
private BsonDocument |
toBsonDocument(Bson document) |
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.
|
private final java.lang.String name
private final ReadPreference readPreference
private final CodecRegistry codecRegistry
private final WriteConcern writeConcern
private final ReadConcern readConcern
private final AsyncOperationExecutor executor
MongoDatabaseImpl(java.lang.String name,
CodecRegistry codecRegistry,
ReadPreference readPreference,
WriteConcern writeConcern,
ReadConcern readConcern,
AsyncOperationExecutor executor)
public java.lang.String getName()
MongoDatabasegetName in interface MongoDatabasepublic CodecRegistry getCodecRegistry()
MongoDatabasegetCodecRegistry in interface MongoDatabaseCodecRegistrypublic ReadPreference getReadPreference()
MongoDatabasegetReadPreference in interface MongoDatabaseReadPreferencepublic WriteConcern getWriteConcern()
MongoDatabasegetWriteConcern in interface MongoDatabaseWriteConcernpublic ReadConcern getReadConcern()
MongoDatabasegetReadConcern in interface MongoDatabaseReadConcernpublic MongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
MongoDatabasewithCodecRegistry in interface MongoDatabasecodecRegistry - the new CodecRegistry for the databasepublic MongoDatabase withReadPreference(ReadPreference readPreference)
MongoDatabasewithReadPreference in interface MongoDatabasereadPreference - the new ReadPreference for the databasepublic MongoDatabase withWriteConcern(WriteConcern writeConcern)
MongoDatabasewithWriteConcern in interface MongoDatabasewriteConcern - the new WriteConcern for the databasepublic MongoDatabase withReadConcern(ReadConcern readConcern)
MongoDatabasewithReadConcern in interface MongoDatabasereadConcern - the new ReadConcern for the databasepublic MongoIterable<java.lang.String> listCollectionNames()
MongoDatabaselistCollectionNames in interface MongoDatabasepublic ListCollectionsIterable<Document> listCollections()
MongoDatabaselistCollections in interface MongoDatabasepublic <TResult> ListCollectionsIterable<TResult> listCollections(java.lang.Class<TResult> resultClass)
MongoDatabaselistCollections in interface MongoDatabaseTResult - the target document type of the iterable.resultClass - the class to decode each document intopublic MongoCollection<Document> getCollection(java.lang.String collectionName)
MongoDatabasegetCollection in interface MongoDatabasecollectionName - the name of the collection to returnMongoNamespace.checkCollectionNameValidity(String)public <TDocument> MongoCollection<TDocument> getCollection(java.lang.String collectionName, java.lang.Class<TDocument> documentClass)
MongoDatabasegetCollection in interface MongoDatabaseTDocument - 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.public void runCommand(Bson command, SingleResultCallback<Document> callback)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabasecommand - the command to be runcallback - the callback that is passed the command resultpublic void runCommand(Bson command, ReadPreference readPreference, SingleResultCallback<Document> callback)
MongoDatabaserunCommand in interface MongoDatabasecommand - the command to be runreadPreference - the ReadPreference to be used when executing the commandcallback - the callback that is passed the command resultpublic <TResult> void runCommand(Bson command, java.lang.Class<TResult> resultClass, SingleResultCallback<TResult> callback)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabaseTResult - 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 resultpublic <TResult> void runCommand(Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass, SingleResultCallback<TResult> callback)
MongoDatabaserunCommand in interface MongoDatabaseTResult - 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 resultpublic void drop(SingleResultCallback<java.lang.Void> callback)
MongoDatabasedrop in interface MongoDatabasecallback - the callback that is completed once the database has been droppedpublic void createCollection(java.lang.String collectionName,
SingleResultCallback<java.lang.Void> callback)
MongoDatabasecreateCollection in interface MongoDatabasecollectionName - the name for the new collection to createcallback - the callback that is completed once the collection has been createdpublic void createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions,
SingleResultCallback<java.lang.Void> callback)
MongoDatabasecreateCollection in interface MongoDatabasecollectionName - the name for the new collection to createcreateCollectionOptions - various options for creating the collectioncallback - the callback that is completed once the collection has been createdpublic void createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
SingleResultCallback<java.lang.Void> callback)
MongoDatabasecreateView in interface MongoDatabaseviewName - 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 createdpublic void createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions,
SingleResultCallback<java.lang.Void> callback)
MongoDatabasecreateView in interface MongoDatabaseviewName - 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 createdprivate java.util.List<BsonDocument> createBsonDocumentList(java.util.List<? extends Bson> pipeline)
private BsonDocument toBsonDocument(Bson document)