TDocument
- The type that this collection will encode documents from and decode documents to.@ThreadSafe
public interface MongoCollection<TDocument>
Note: Additions to this interface will not be considered to break binary compatibility.
Modifier and Type | Method and Description |
---|---|
AggregatePublisher<org.bson.Document> |
aggregate(List<? extends org.bson.conversions.Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.
|
<TResult> AggregatePublisher<TResult> |
aggregate(List<? extends org.bson.conversions.Bson> pipeline,
Class<TResult> clazz)
Aggregates documents according to the specified aggregation pipeline.
|
org.reactivestreams.Publisher<com.mongodb.bulk.BulkWriteResult> |
bulkWrite(List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.
|
org.reactivestreams.Publisher<com.mongodb.bulk.BulkWriteResult> |
bulkWrite(List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>> requests,
com.mongodb.client.model.BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.
|
org.reactivestreams.Publisher<Long> |
count()
Counts the number of documents in the collection.
|
org.reactivestreams.Publisher<Long> |
count(org.bson.conversions.Bson filter)
Counts the number of documents in the collection according to the given options.
|
org.reactivestreams.Publisher<Long> |
count(org.bson.conversions.Bson filter,
com.mongodb.client.model.CountOptions options)
Counts the number of documents in the collection according to the given options.
|
org.reactivestreams.Publisher<String> |
createIndex(org.bson.conversions.Bson key)
Creates an index.
|
org.reactivestreams.Publisher<String> |
createIndex(org.bson.conversions.Bson key,
com.mongodb.client.model.IndexOptions options)
Creates an index.
|
org.reactivestreams.Publisher<String> |
createIndexes(List<com.mongodb.client.model.IndexModel> indexes)
Create multiple indexes.
|
org.reactivestreams.Publisher<com.mongodb.client.result.DeleteResult> |
deleteMany(org.bson.conversions.Bson filter)
Removes all documents from the collection that match the given query filter.
|
org.reactivestreams.Publisher<com.mongodb.client.result.DeleteResult> |
deleteOne(org.bson.conversions.Bson filter)
Removes at most one document from the collection that matches the given filter.
|
<TResult> DistinctPublisher<TResult> |
distinct(String fieldName,
org.bson.conversions.Bson filter,
Class<TResult> resultClass)
Gets the distinct values of the specified field name.
|
<TResult> DistinctPublisher<TResult> |
distinct(String fieldName,
Class<TResult> resultClass)
Gets the distinct values of the specified field name.
|
org.reactivestreams.Publisher<Success> |
drop()
Drops this collection from the Database.
|
org.reactivestreams.Publisher<Success> |
dropIndex(org.bson.conversions.Bson keys)
Drops the index given the keys used to create it.
|
org.reactivestreams.Publisher<Success> |
dropIndex(String indexName)
Drops the given index.
|
org.reactivestreams.Publisher<Success> |
dropIndexes()
Drop all the indexes on this collection, except for the default on _id.
|
FindPublisher<TDocument> |
find()
Finds all documents in the collection.
|
FindPublisher<TDocument> |
find(org.bson.conversions.Bson filter)
Finds all documents in the collection.
|
<TResult> FindPublisher<TResult> |
find(org.bson.conversions.Bson filter,
Class<TResult> clazz)
Finds all documents in the collection.
|
<TResult> FindPublisher<TResult> |
find(Class<TResult> clazz)
Finds all documents in the collection.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndDelete(org.bson.conversions.Bson filter)
Atomically find a document and remove it.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndDelete(org.bson.conversions.Bson filter,
com.mongodb.client.model.FindOneAndDeleteOptions options)
Atomically find a document and remove it.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndReplace(org.bson.conversions.Bson filter,
TDocument replacement)
Atomically find a document and replace it.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndReplace(org.bson.conversions.Bson filter,
TDocument replacement,
com.mongodb.client.model.FindOneAndReplaceOptions options)
Atomically find a document and replace it.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndUpdate(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update)
Atomically find a document and update it.
|
org.reactivestreams.Publisher<TDocument> |
findOneAndUpdate(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update,
com.mongodb.client.model.FindOneAndUpdateOptions options)
Atomically find a document and update it.
|
org.bson.codecs.configuration.CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoCollection.
|
Class<TDocument> |
getDocumentClass()
Get the class of documents stored in this collection.
|
com.mongodb.MongoNamespace |
getNamespace()
Gets the namespace of this collection.
|
com.mongodb.ReadPreference |
getReadPreference()
Get the read preference for the MongoCollection.
|
com.mongodb.WriteConcern |
getWriteConcern()
Get the write concern for the MongoCollection.
|
org.reactivestreams.Publisher<Success> |
insertMany(List<? extends TDocument> documents)
Inserts a batch of documents.
|
org.reactivestreams.Publisher<Success> |
insertMany(List<? extends TDocument> documents,
com.mongodb.client.model.InsertManyOptions options)
Inserts a batch of documents.
|
org.reactivestreams.Publisher<Success> |
insertOne(TDocument document)
Inserts the provided document.
|
ListIndexesPublisher<org.bson.Document> |
listIndexes()
Get all the indexes in this collection.
|
<TResult> ListIndexesPublisher<TResult> |
listIndexes(Class<TResult> clazz)
Get all the indexes in this collection.
|
MapReducePublisher<org.bson.Document> |
mapReduce(String mapFunction,
String reduceFunction)
Aggregates documents according to the specified map-reduce function.
|
<TResult> MapReducePublisher<TResult> |
mapReduce(String mapFunction,
String reduceFunction,
Class<TResult> clazz)
Aggregates documents according to the specified map-reduce function.
|
org.reactivestreams.Publisher<Success> |
renameCollection(com.mongodb.MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.
|
org.reactivestreams.Publisher<Success> |
renameCollection(com.mongodb.MongoNamespace newCollectionNamespace,
com.mongodb.client.model.RenameCollectionOptions options)
Rename the collection with oldCollectionName to the newCollectionName.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
replaceOne(org.bson.conversions.Bson filter,
TDocument replacement)
Replace a document in the collection according to the specified arguments.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
replaceOne(org.bson.conversions.Bson filter,
TDocument replacement,
com.mongodb.client.model.UpdateOptions options)
Replace a document in the collection according to the specified arguments.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
updateMany(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update)
Update a single document in the collection according to the specified arguments.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
updateMany(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update,
com.mongodb.client.model.UpdateOptions options)
Update a single document in the collection according to the specified arguments.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
updateOne(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update)
Update a single document in the collection according to the specified arguments.
|
org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> |
updateOne(org.bson.conversions.Bson filter,
org.bson.conversions.Bson update,
com.mongodb.client.model.UpdateOptions options)
Update a single document in the collection according to the specified arguments.
|
MongoCollection<TDocument> |
withCodecRegistry(org.bson.codecs.configuration.CodecRegistry codecRegistry)
Create a new MongoCollection instance with a different codec registry.
|
<NewTDocument> |
withDocumentClass(Class<NewTDocument> clazz)
Create a new MongoCollection instance with a different default class to cast any documents returned from the database into..
|
MongoCollection<TDocument> |
withReadPreference(com.mongodb.ReadPreference readPreference)
Create a new MongoCollection instance with a different read preference.
|
MongoCollection<TDocument> |
withWriteConcern(com.mongodb.WriteConcern writeConcern)
Create a new MongoCollection instance with a different write concern.
|
com.mongodb.MongoNamespace getNamespace()
Class<TDocument> getDocumentClass()
org.bson.codecs.configuration.CodecRegistry getCodecRegistry()
CodecRegistry
com.mongodb.ReadPreference getReadPreference()
ReadPreference
com.mongodb.WriteConcern getWriteConcern()
WriteConcern
<NewTDocument> MongoCollection<NewTDocument> withDocumentClass(Class<NewTDocument> clazz)
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.MongoCollection<TDocument> withCodecRegistry(org.bson.codecs.configuration.CodecRegistry codecRegistry)
codecRegistry
- the new CodecRegistry
for the collectionMongoCollection<TDocument> withReadPreference(com.mongodb.ReadPreference readPreference)
readPreference
- the new ReadPreference
for the collectionMongoCollection<TDocument> withWriteConcern(com.mongodb.WriteConcern writeConcern)
writeConcern
- the new WriteConcern
for the collectionorg.reactivestreams.Publisher<Long> count()
org.reactivestreams.Publisher<Long> count(org.bson.conversions.Bson filter)
filter
- the query filterorg.reactivestreams.Publisher<Long> count(org.bson.conversions.Bson filter, com.mongodb.client.model.CountOptions options)
filter
- the query filteroptions
- the options describing the count<TResult> DistinctPublisher<TResult> distinct(String fieldName, Class<TResult> resultClass)
TResult
- the target type of the iterable.fieldName
- the field nameresultClass
- the default class to cast any distinct items into.<TResult> DistinctPublisher<TResult> distinct(String fieldName, org.bson.conversions.Bson filter, Class<TResult> resultClass)
TResult
- the target type of the iterable.fieldName
- the field namefilter
- the query filterresultClass
- the default class to cast any distinct items into.FindPublisher<TDocument> find()
<TResult> FindPublisher<TResult> find(Class<TResult> clazz)
TResult
- the target document type of the iterable.clazz
- the class to decode each document intoFindPublisher<TDocument> find(org.bson.conversions.Bson filter)
filter
- the query filter<TResult> FindPublisher<TResult> find(org.bson.conversions.Bson filter, Class<TResult> clazz)
TResult
- the target document type of the iterable.filter
- the query filterclazz
- the class to decode each document intoAggregatePublisher<org.bson.Document> aggregate(List<? extends org.bson.conversions.Bson> pipeline)
pipeline
- the aggregate pipeline<TResult> AggregatePublisher<TResult> aggregate(List<? extends org.bson.conversions.Bson> pipeline, Class<TResult> clazz)
TResult
- the target document type of the iterable.pipeline
- the aggregate pipelineclazz
- the class to decode each document intoMapReducePublisher<org.bson.Document> mapReduce(String mapFunction, String reduceFunction)
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.<TResult> MapReducePublisher<TResult> mapReduce(String mapFunction, String reduceFunction, Class<TResult> clazz)
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.clazz
- the class to decode each resulting document into.org.reactivestreams.Publisher<com.mongodb.bulk.BulkWriteResult> bulkWrite(List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>> requests)
requests
- the writes to executeorg.reactivestreams.Publisher<com.mongodb.bulk.BulkWriteResult> bulkWrite(List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>> requests, com.mongodb.client.model.BulkWriteOptions options)
requests
- the writes to executeoptions
- the options to apply to the bulk write operationorg.reactivestreams.Publisher<Success> insertOne(TDocument document)
document
- the document to insertorg.reactivestreams.Publisher<Success> insertMany(List<? extends TDocument> documents)
documents
- the documents to insertorg.reactivestreams.Publisher<Success> insertMany(List<? extends TDocument> documents, com.mongodb.client.model.InsertManyOptions options)
documents
- the documents to insertoptions
- the options to apply to the operationorg.reactivestreams.Publisher<com.mongodb.client.result.DeleteResult> deleteOne(org.bson.conversions.Bson filter)
filter
- the query filter to apply the the delete operationorg.reactivestreams.Publisher<com.mongodb.client.result.DeleteResult> deleteMany(org.bson.conversions.Bson filter)
filter
- the query filter to apply the the delete operationorg.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> replaceOne(org.bson.conversions.Bson filter, TDocument replacement)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentorg.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> replaceOne(org.bson.conversions.Bson filter, TDocument replacement, com.mongodb.client.model.UpdateOptions options)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the replace operationorg.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> updateOne(org.bson.conversions.Bson filter, org.bson.conversions.Bson update)
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.org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> updateOne(org.bson.conversions.Bson filter, org.bson.conversions.Bson update, com.mongodb.client.model.UpdateOptions options)
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 update operationorg.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> updateMany(org.bson.conversions.Bson filter, org.bson.conversions.Bson update)
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.org.reactivestreams.Publisher<com.mongodb.client.result.UpdateResult> updateMany(org.bson.conversions.Bson filter, org.bson.conversions.Bson update, com.mongodb.client.model.UpdateOptions options)
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 update operationorg.reactivestreams.Publisher<TDocument> findOneAndDelete(org.bson.conversions.Bson filter)
filter
- the query filter to find the document withorg.reactivestreams.Publisher<TDocument> findOneAndDelete(org.bson.conversions.Bson filter, com.mongodb.client.model.FindOneAndDeleteOptions options)
filter
- the query filter to find the document withoptions
- the options to apply to the operationorg.reactivestreams.Publisher<TDocument> findOneAndReplace(org.bson.conversions.Bson filter, TDocument replacement)
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 returnedorg.reactivestreams.Publisher<TDocument> findOneAndReplace(org.bson.conversions.Bson filter, TDocument replacement, com.mongodb.client.model.FindOneAndReplaceOptions options)
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 returnedorg.reactivestreams.Publisher<TDocument> findOneAndUpdate(org.bson.conversions.Bson filter, org.bson.conversions.Bson update)
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.org.reactivestreams.Publisher<TDocument> findOneAndUpdate(org.bson.conversions.Bson filter, org.bson.conversions.Bson update, com.mongodb.client.model.FindOneAndUpdateOptions options)
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 returnedorg.reactivestreams.Publisher<Success> drop()
org.reactivestreams.Publisher<String> createIndex(org.bson.conversions.Bson key)
key
- an object describing the index key(s), which may not be null.org.reactivestreams.Publisher<String> createIndex(org.bson.conversions.Bson key, com.mongodb.client.model.IndexOptions options)
key
- an object describing the index key(s), which may not be null.options
- the options for the indexorg.reactivestreams.Publisher<String> createIndexes(List<com.mongodb.client.model.IndexModel> indexes)
indexes
- the list of indexesListIndexesPublisher<org.bson.Document> listIndexes()
<TResult> ListIndexesPublisher<TResult> listIndexes(Class<TResult> clazz)
TResult
- the target document type of the iterable.clazz
- the class to decode each document intoorg.reactivestreams.Publisher<Success> dropIndex(String indexName)
indexName
- the name of the index to removeorg.reactivestreams.Publisher<Success> dropIndex(org.bson.conversions.Bson keys)
keys
- the keys of the index to removeorg.reactivestreams.Publisher<Success> dropIndexes()
org.reactivestreams.Publisher<Success> renameCollection(com.mongodb.MongoNamespace newCollectionNamespace)
newCollectionNamespace
- the namespace the collection will be renamed toorg.reactivestreams.Publisher<Success> renameCollection(com.mongodb.MongoNamespace newCollectionNamespace, com.mongodb.client.model.RenameCollectionOptions options)
newCollectionNamespace
- the name the collection will be renamed tooptions
- the options for renaming a collection