class MongoDatabaseImpl extends java.lang.Object implements MongoDatabase
Modifier and Type | Field and Description |
---|---|
private CodecRegistry |
codecRegistry |
private OperationExecutor |
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,
OperationExecutor 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)
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(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.
|
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.
|
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.
|
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 OperationExecutor executor
MongoDatabaseImpl(java.lang.String name, CodecRegistry codecRegistry, ReadPreference readPreference, WriteConcern writeConcern, ReadConcern readConcern, OperationExecutor executor)
public java.lang.String getName()
MongoDatabase
getName
in interface MongoDatabase
public CodecRegistry getCodecRegistry()
MongoDatabase
getCodecRegistry
in interface MongoDatabase
CodecRegistry
public ReadPreference getReadPreference()
MongoDatabase
getReadPreference
in interface MongoDatabase
ReadPreference
public WriteConcern getWriteConcern()
MongoDatabase
getWriteConcern
in interface MongoDatabase
WriteConcern
public ReadConcern getReadConcern()
MongoDatabase
getReadConcern
in interface MongoDatabase
ReadConcern
public MongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
MongoDatabase
withCodecRegistry
in interface MongoDatabase
codecRegistry
- the new CodecRegistry
for the databasepublic MongoDatabase withReadPreference(ReadPreference readPreference)
MongoDatabase
withReadPreference
in interface MongoDatabase
readPreference
- the new ReadPreference
for the databasepublic MongoDatabase withWriteConcern(WriteConcern writeConcern)
MongoDatabase
withWriteConcern
in interface MongoDatabase
writeConcern
- the new WriteConcern
for the databasepublic MongoDatabase withReadConcern(ReadConcern readConcern)
MongoDatabase
withReadConcern
in interface MongoDatabase
readConcern
- the new ReadConcern
for the databasepublic MongoCollection<Document> getCollection(java.lang.String collectionName)
MongoDatabase
getCollection
in interface MongoDatabase
collectionName
- the name of the collection to returnMongoNamespace.checkCollectionNameValidity(String)
public <TDocument> MongoCollection<TDocument> getCollection(java.lang.String collectionName, java.lang.Class<TDocument> documentClass)
MongoDatabase
getCollection
in interface MongoDatabase
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.public Document runCommand(Bson command)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
command
- the command to be runpublic Document runCommand(Bson command, ReadPreference readPreference)
MongoDatabase
runCommand
in interface MongoDatabase
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandpublic <TResult> TResult runCommand(Bson command, java.lang.Class<TResult> resultClass)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
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.public <TResult> TResult runCommand(Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
MongoDatabase
runCommand
in interface MongoDatabase
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.public void drop()
MongoDatabase
drop
in interface MongoDatabase
public MongoIterable<java.lang.String> listCollectionNames()
MongoDatabase
listCollectionNames
in interface MongoDatabase
public ListCollectionsIterable<Document> listCollections()
MongoDatabase
listCollections
in interface MongoDatabase
public <TResult> ListCollectionsIterable<TResult> listCollections(java.lang.Class<TResult> resultClass)
MongoDatabase
listCollections
in interface MongoDatabase
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intopublic void createCollection(java.lang.String collectionName)
MongoDatabase
createCollection
in interface MongoDatabase
collectionName
- the name for the new collection to createpublic void createCollection(java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
MongoDatabase
createCollection
in interface MongoDatabase
collectionName
- the name for the new collection to createcreateCollectionOptions
- various options for creating the collectionpublic void createView(java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline)
MongoDatabase
createView
in interface MongoDatabase
viewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewpublic void createView(java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
MongoDatabase
createView
in interface MongoDatabase
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 viewprivate java.util.List<BsonDocument> createBsonDocumentList(java.util.List<? extends Bson> pipeline)
private BsonDocument toBsonDocument(Bson document)