class MongoCollectionImpl<TDocument> extends java.lang.Object implements MongoCollection<TDocument>
Modifier and Type | Field and Description |
---|---|
private CodecRegistry |
codecRegistry |
private java.lang.Class<TDocument> |
documentClass |
private OperationExecutor |
executor |
private MongoNamespace |
namespace |
private ReadConcern |
readConcern |
private ReadPreference |
readPreference |
private WriteConcern |
writeConcern |
Constructor and Description |
---|
MongoCollectionImpl(MongoNamespace namespace,
java.lang.Class<TDocument> documentClass,
CodecRegistry codecRegistry,
ReadPreference readPreference,
WriteConcern writeConcern,
ReadConcern readConcern,
OperationExecutor executor) |
Modifier and Type | Method and Description |
---|---|
AggregateIterable<TDocument> |
aggregate(java.util.List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.
|
<TResult> AggregateIterable<TResult> |
aggregate(java.util.List<? extends Bson> pipeline,
java.lang.Class<TResult> resultClass)
Aggregates documents according to the specified aggregation pipeline.
|
BulkWriteResult |
bulkWrite(java.util.List<? extends WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.
|
BulkWriteResult |
bulkWrite(java.util.List<? extends WriteModel<? extends TDocument>> requests,
BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.
|
long |
count()
Counts the number of documents in the collection.
|
long |
count(Bson filter)
Counts the number of documents in the collection according to the given options.
|
long |
count(Bson filter,
CountOptions options)
Counts the number of documents in the collection according to the given options.
|
java.lang.String |
createIndex(Bson keys)
Create an index with the given keys.
|
java.lang.String |
createIndex(Bson keys,
IndexOptions indexOptions)
Create an index with the given keys and options.
|
java.util.List<java.lang.String> |
createIndexes(java.util.List<IndexModel> indexes)
Create multiple indexes.
|
private DeleteResult |
delete(Bson filter,
DeleteOptions deleteOptions,
boolean multi) |
DeleteResult |
deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter.
|
DeleteResult |
deleteMany(Bson filter,
DeleteOptions options)
Removes all documents from the collection that match the given query filter.
|
DeleteResult |
deleteOne(Bson filter)
Removes at most one document from the collection that matches the given filter.
|
DeleteResult |
deleteOne(Bson filter,
DeleteOptions options)
Removes at most one document from the collection that matches the given filter.
|
<TResult> DistinctIterable<TResult> |
distinct(java.lang.String fieldName,
Bson filter,
java.lang.Class<TResult> resultClass)
Gets the distinct values of the specified field name.
|
<TResult> DistinctIterable<TResult> |
distinct(java.lang.String fieldName,
java.lang.Class<TResult> resultClass)
Gets the distinct values of the specified field name.
|
private BsonDocument |
documentToBsonDocument(TDocument document) |
void |
drop()
Drops this collection from the Database.
|
void |
dropIndex(Bson keys)
Drops the index given the keys used to create it.
|
void |
dropIndex(java.lang.String indexName)
Drops the index given its name.
|
void |
dropIndexes()
Drop all the indexes on this collection, except for the default on _id.
|
private BulkWriteResult |
executeSingleWriteRequest(WriteRequest request,
java.lang.Boolean bypassDocumentValidation) |
FindIterable<TDocument> |
find()
Finds all documents in the collection.
|
FindIterable<TDocument> |
find(Bson filter)
Finds all documents in the collection.
|
<TResult> FindIterable<TResult> |
find(Bson filter,
java.lang.Class<TResult> resultClass)
Finds all documents in the collection.
|
<TResult> FindIterable<TResult> |
find(java.lang.Class<TResult> resultClass)
Finds all documents in the collection.
|
TDocument |
findOneAndDelete(Bson filter)
Atomically find a document and remove it.
|
TDocument |
findOneAndDelete(Bson filter,
FindOneAndDeleteOptions options)
Atomically find a document and remove it.
|
TDocument |
findOneAndReplace(Bson filter,
TDocument replacement)
Atomically find a document and replace it.
|
TDocument |
findOneAndReplace(Bson filter,
TDocument replacement,
FindOneAndReplaceOptions options)
Atomically find a document and replace it.
|
TDocument |
findOneAndUpdate(Bson filter,
Bson update)
Atomically find a document and update it.
|
TDocument |
findOneAndUpdate(Bson filter,
Bson update,
FindOneAndUpdateOptions options)
Atomically find a document and update it.
|
private Codec<TDocument> |
getCodec() |
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoCollection.
|
java.lang.Class<TDocument> |
getDocumentClass()
Get the class of documents stored in this collection.
|
MongoNamespace |
getNamespace()
Gets the namespace of this collection.
|
ReadConcern |
getReadConcern()
Get the read concern for the MongoCollection.
|
ReadPreference |
getReadPreference()
Get the read preference for the MongoCollection.
|
WriteConcern |
getWriteConcern()
Get the write concern for the MongoCollection.
|
void |
insertMany(java.util.List<? extends TDocument> documents)
Inserts one or more documents.
|
void |
insertMany(java.util.List<? extends TDocument> documents,
InsertManyOptions options)
Inserts one or more documents.
|
void |
insertOne(TDocument document)
Inserts the provided document.
|
void |
insertOne(TDocument document,
InsertOneOptions options)
Inserts the provided document.
|
ListIndexesIterable<Document> |
listIndexes()
Get all the indexes in this collection.
|
<TResult> ListIndexesIterable<TResult> |
listIndexes(java.lang.Class<TResult> resultClass)
Get all the indexes in this collection.
|
MapReduceIterable<TDocument> |
mapReduce(java.lang.String mapFunction,
java.lang.String reduceFunction)
Aggregates documents according to the specified map-reduce function.
|
<TResult> MapReduceIterable<TResult> |
mapReduce(java.lang.String mapFunction,
java.lang.String reduceFunction,
java.lang.Class<TResult> resultClass)
Aggregates documents according to the specified map-reduce function.
|
void |
renameCollection(MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.
|
void |
renameCollection(MongoNamespace newCollectionNamespace,
RenameCollectionOptions renameCollectionOptions)
Rename the collection with oldCollectionName to the newCollectionName.
|
UpdateResult |
replaceOne(Bson filter,
TDocument replacement)
Replace a document in the collection according to the specified arguments.
|
UpdateResult |
replaceOne(Bson filter,
TDocument replacement,
UpdateOptions updateOptions)
Replace a document in the collection according to the specified arguments.
|
private BsonDocument |
toBsonDocument(Bson bson) |
private UpdateResult |
toUpdateResult(BulkWriteResult result) |
private WriteConcernResult |
translateBulkWriteResult(WriteRequest request,
BulkWriteResult writeResult) |
private UpdateResult |
update(Bson filter,
Bson update,
UpdateOptions updateOptions,
boolean multi) |
UpdateResult |
updateMany(Bson filter,
Bson update)
Update all documents in the collection according to the specified arguments.
|
UpdateResult |
updateMany(Bson filter,
Bson update,
UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.
|
UpdateResult |
updateOne(Bson filter,
Bson update)
Update a single document in the collection according to the specified arguments.
|
UpdateResult |
updateOne(Bson filter,
Bson update,
UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.
|
MongoCollection<TDocument> |
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoCollection instance with a different codec registry.
|
<NewTDocument> |
withDocumentClass(java.lang.Class<NewTDocument> clazz)
Create a new MongoCollection instance with a different default class to cast any documents returned from the database into..
|
MongoCollection<TDocument> |
withReadConcern(ReadConcern readConcern)
Create a new MongoCollection instance with a different read concern.
|
MongoCollection<TDocument> |
withReadPreference(ReadPreference readPreference)
Create a new MongoCollection instance with a different read preference.
|
MongoCollection<TDocument> |
withWriteConcern(WriteConcern writeConcern)
Create a new MongoCollection instance with a different write concern.
|
private final MongoNamespace namespace
private final java.lang.Class<TDocument> documentClass
private final ReadPreference readPreference
private final CodecRegistry codecRegistry
private final WriteConcern writeConcern
private final ReadConcern readConcern
private final OperationExecutor executor
MongoCollectionImpl(MongoNamespace namespace, java.lang.Class<TDocument> documentClass, CodecRegistry codecRegistry, ReadPreference readPreference, WriteConcern writeConcern, ReadConcern readConcern, OperationExecutor executor)
public MongoNamespace getNamespace()
MongoCollection
getNamespace
in interface MongoCollection<TDocument>
public java.lang.Class<TDocument> getDocumentClass()
MongoCollection
getDocumentClass
in interface MongoCollection<TDocument>
public CodecRegistry getCodecRegistry()
MongoCollection
getCodecRegistry
in interface MongoCollection<TDocument>
CodecRegistry
public ReadPreference getReadPreference()
MongoCollection
getReadPreference
in interface MongoCollection<TDocument>
ReadPreference
public WriteConcern getWriteConcern()
MongoCollection
getWriteConcern
in interface MongoCollection<TDocument>
WriteConcern
public ReadConcern getReadConcern()
MongoCollection
getReadConcern
in interface MongoCollection<TDocument>
ReadConcern
public <NewTDocument> MongoCollection<NewTDocument> withDocumentClass(java.lang.Class<NewTDocument> clazz)
MongoCollection
withDocumentClass
in interface MongoCollection<TDocument>
NewTDocument
- The type that the new collection will encode documents from and decode documents toclazz
- the default class to cast any documents returned from the database into.public MongoCollection<TDocument> withCodecRegistry(CodecRegistry codecRegistry)
MongoCollection
withCodecRegistry
in interface MongoCollection<TDocument>
codecRegistry
- the new CodecRegistry
for the collectionpublic MongoCollection<TDocument> withReadPreference(ReadPreference readPreference)
MongoCollection
withReadPreference
in interface MongoCollection<TDocument>
readPreference
- the new ReadPreference
for the collectionpublic MongoCollection<TDocument> withWriteConcern(WriteConcern writeConcern)
MongoCollection
withWriteConcern
in interface MongoCollection<TDocument>
writeConcern
- the new WriteConcern
for the collectionpublic MongoCollection<TDocument> withReadConcern(ReadConcern readConcern)
MongoCollection
withReadConcern
in interface MongoCollection<TDocument>
readConcern
- the new ReadConcern
for the collectionpublic long count()
MongoCollection
count
in interface MongoCollection<TDocument>
public long count(Bson filter)
MongoCollection
count
in interface MongoCollection<TDocument>
filter
- the query filterpublic long count(Bson filter, CountOptions options)
MongoCollection
count
in interface MongoCollection<TDocument>
filter
- the query filteroptions
- the options describing the countpublic <TResult> DistinctIterable<TResult> distinct(java.lang.String fieldName, java.lang.Class<TResult> resultClass)
MongoCollection
distinct
in interface MongoCollection<TDocument>
TResult
- the target type of the iterable.fieldName
- the field nameresultClass
- the class to cast any distinct items into.public <TResult> DistinctIterable<TResult> distinct(java.lang.String fieldName, Bson filter, java.lang.Class<TResult> resultClass)
MongoCollection
distinct
in interface MongoCollection<TDocument>
TResult
- the target type of the iterable.fieldName
- the field namefilter
- the query filterresultClass
- the class to cast any distinct items into.public FindIterable<TDocument> find()
MongoCollection
find
in interface MongoCollection<TDocument>
public <TResult> FindIterable<TResult> find(java.lang.Class<TResult> resultClass)
MongoCollection
find
in interface MongoCollection<TDocument>
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intopublic FindIterable<TDocument> find(Bson filter)
MongoCollection
find
in interface MongoCollection<TDocument>
filter
- the query filterpublic <TResult> FindIterable<TResult> find(Bson filter, java.lang.Class<TResult> resultClass)
MongoCollection
find
in interface MongoCollection<TDocument>
TResult
- the target document type of the iterable.filter
- the query filterresultClass
- the class to decode each document intopublic AggregateIterable<TDocument> aggregate(java.util.List<? extends Bson> pipeline)
MongoCollection
aggregate
in interface MongoCollection<TDocument>
pipeline
- the aggregate pipelinepublic <TResult> AggregateIterable<TResult> aggregate(java.util.List<? extends Bson> pipeline, java.lang.Class<TResult> resultClass)
MongoCollection
aggregate
in interface MongoCollection<TDocument>
TResult
- the target document type of the iterable.pipeline
- the aggregate pipelineresultClass
- the class to decode each document intopublic MapReduceIterable<TDocument> mapReduce(java.lang.String mapFunction, java.lang.String reduceFunction)
MongoCollection
mapReduce
in interface MongoCollection<TDocument>
mapFunction
- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction
- A JavaScript function that "reduces" to a single object all the values associated with a particular key.public <TResult> MapReduceIterable<TResult> mapReduce(java.lang.String mapFunction, java.lang.String reduceFunction, java.lang.Class<TResult> resultClass)
MongoCollection
mapReduce
in interface MongoCollection<TDocument>
TResult
- the target document type of the iterable.mapFunction
- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction
- A JavaScript function that "reduces" to a single object all the values associated with a particular key.resultClass
- the class to decode each resulting document into.public BulkWriteResult bulkWrite(java.util.List<? extends WriteModel<? extends TDocument>> requests)
MongoCollection
bulkWrite
in interface MongoCollection<TDocument>
requests
- the writes to executepublic BulkWriteResult bulkWrite(java.util.List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options)
MongoCollection
bulkWrite
in interface MongoCollection<TDocument>
requests
- the writes to executeoptions
- the options to apply to the bulk write operationpublic void insertOne(TDocument document)
MongoCollection
insertOne
in interface MongoCollection<TDocument>
document
- the document to insertpublic void insertOne(TDocument document, InsertOneOptions options)
MongoCollection
insertOne
in interface MongoCollection<TDocument>
document
- the document to insertoptions
- the options to apply to the operationpublic void insertMany(java.util.List<? extends TDocument> documents)
MongoCollection
bulkWrite
methodinsertMany
in interface MongoCollection<TDocument>
documents
- the documents to insertMongoCollection.bulkWrite(java.util.List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>>)
public void insertMany(java.util.List<? extends TDocument> documents, InsertManyOptions options)
MongoCollection
bulkWrite
methodinsertMany
in interface MongoCollection<TDocument>
documents
- the documents to insertoptions
- the options to apply to the operationpublic DeleteResult deleteOne(Bson filter)
MongoCollection
deleteOne
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the delete operationpublic DeleteResult deleteOne(Bson filter, DeleteOptions options)
MongoCollection
deleteOne
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operationpublic DeleteResult deleteMany(Bson filter)
MongoCollection
deleteMany
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the delete operationpublic DeleteResult deleteMany(Bson filter, DeleteOptions options)
MongoCollection
deleteMany
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operationpublic UpdateResult replaceOne(Bson filter, TDocument replacement)
MongoCollection
replaceOne
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentpublic UpdateResult replaceOne(Bson filter, TDocument replacement, UpdateOptions updateOptions)
MongoCollection
replaceOne
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentupdateOptions
- the options to apply to the replace operationpublic UpdateResult updateOne(Bson filter, Bson update)
MongoCollection
updateOne
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.public UpdateResult updateOne(Bson filter, Bson update, UpdateOptions updateOptions)
MongoCollection
updateOne
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operationpublic UpdateResult updateMany(Bson filter, Bson update)
MongoCollection
updateMany
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.public UpdateResult updateMany(Bson filter, Bson update, UpdateOptions updateOptions)
MongoCollection
updateMany
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operationpublic TDocument findOneAndDelete(Bson filter)
MongoCollection
findOneAndDelete
in interface MongoCollection<TDocument>
filter
- the query filter to find the document withpublic TDocument findOneAndDelete(Bson filter, FindOneAndDeleteOptions options)
MongoCollection
findOneAndDelete
in interface MongoCollection<TDocument>
filter
- the query filter to find the document withoptions
- the options to apply to the operationpublic TDocument findOneAndReplace(Bson filter, TDocument replacement)
MongoCollection
findOneAndReplace
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedpublic TDocument findOneAndReplace(Bson filter, TDocument replacement, FindOneAndReplaceOptions options)
MongoCollection
findOneAndReplace
in interface MongoCollection<TDocument>
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operationreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedpublic TDocument findOneAndUpdate(Bson filter, Bson update)
MongoCollection
findOneAndUpdate
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.public TDocument findOneAndUpdate(Bson filter, Bson update, FindOneAndUpdateOptions options)
MongoCollection
findOneAndUpdate
in interface MongoCollection<TDocument>
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.options
- the options to apply to the operationreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedpublic void drop()
MongoCollection
drop
in interface MongoCollection<TDocument>
public java.lang.String createIndex(Bson keys)
MongoCollection
createIndex
in interface MongoCollection<TDocument>
keys
- an object describing the index key(s), which may not be null.public java.lang.String createIndex(Bson keys, IndexOptions indexOptions)
MongoCollection
createIndex
in interface MongoCollection<TDocument>
keys
- an object describing the index key(s), which may not be null.indexOptions
- the options for the indexpublic java.util.List<java.lang.String> createIndexes(java.util.List<IndexModel> indexes)
MongoCollection
createIndexes
in interface MongoCollection<TDocument>
indexes
- the list of indexespublic ListIndexesIterable<Document> listIndexes()
MongoCollection
listIndexes
in interface MongoCollection<TDocument>
public <TResult> ListIndexesIterable<TResult> listIndexes(java.lang.Class<TResult> resultClass)
MongoCollection
listIndexes
in interface MongoCollection<TDocument>
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intopublic void dropIndex(java.lang.String indexName)
MongoCollection
dropIndex
in interface MongoCollection<TDocument>
indexName
- the name of the index to removepublic void dropIndex(Bson keys)
MongoCollection
dropIndex
in interface MongoCollection<TDocument>
keys
- the keys of the index to removepublic void dropIndexes()
MongoCollection
dropIndexes
in interface MongoCollection<TDocument>
public void renameCollection(MongoNamespace newCollectionNamespace)
MongoCollection
renameCollection
in interface MongoCollection<TDocument>
newCollectionNamespace
- the namespace the collection will be renamed topublic void renameCollection(MongoNamespace newCollectionNamespace, RenameCollectionOptions renameCollectionOptions)
MongoCollection
renameCollection
in interface MongoCollection<TDocument>
newCollectionNamespace
- the name the collection will be renamed torenameCollectionOptions
- the options for renaming a collectionprivate DeleteResult delete(Bson filter, DeleteOptions deleteOptions, boolean multi)
private UpdateResult update(Bson filter, Bson update, UpdateOptions updateOptions, boolean multi)
private BulkWriteResult executeSingleWriteRequest(WriteRequest request, java.lang.Boolean bypassDocumentValidation)
private WriteConcernResult translateBulkWriteResult(WriteRequest request, BulkWriteResult writeResult)
private UpdateResult toUpdateResult(BulkWriteResult result)
private BsonDocument documentToBsonDocument(TDocument document)
private BsonDocument toBsonDocument(Bson bson)