Interface MongoCollection<TDocument>
-
- Type Parameters:
TDocument
- The type that this collection will encode documents from and decode documents to.
@ThreadSafe public interface MongoCollection<TDocument>
The MongoCollection interface.Note: Additions to this interface will not be considered to break binary compatibility.
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AggregatePublisher<TDocument>
aggregate(ClientSession clientSession, List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.<TResult> AggregatePublisher<TResult>
aggregate(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> clazz)
Aggregates documents according to the specified aggregation pipeline.AggregatePublisher<TDocument>
aggregate(List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.<TResult> AggregatePublisher<TResult>
aggregate(List<? extends Bson> pipeline, Class<TResult> clazz)
Aggregates documents according to the specified aggregation pipeline.Publisher<BulkWriteResult>
bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.Publisher<BulkWriteResult>
bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.Publisher<BulkWriteResult>
bulkWrite(List<? extends WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.Publisher<BulkWriteResult>
bulkWrite(List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.Publisher<Long>
countDocuments()
Counts the number of documents in the collection.Publisher<Long>
countDocuments(ClientSession clientSession)
Counts the number of documents in the collection.Publisher<Long>
countDocuments(ClientSession clientSession, Bson filter)
Counts the number of documents in the collection according to the given options.Publisher<Long>
countDocuments(ClientSession clientSession, Bson filter, CountOptions options)
Counts the number of documents in the collection according to the given options.Publisher<Long>
countDocuments(Bson filter)
Counts the number of documents in the collection according to the given options.Publisher<Long>
countDocuments(Bson filter, CountOptions options)
Counts the number of documents in the collection according to the given options.Publisher<String>
createIndex(ClientSession clientSession, Bson key)
Creates an index.Publisher<String>
createIndex(ClientSession clientSession, Bson key, IndexOptions options)
Creates an index.Publisher<String>
createIndex(Bson key)
Creates an index.Publisher<String>
createIndex(Bson key, IndexOptions options)
Creates an index.Publisher<String>
createIndexes(ClientSession clientSession, List<IndexModel> indexes)
Create multiple indexes.Publisher<String>
createIndexes(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.Publisher<String>
createIndexes(List<IndexModel> indexes)
Create multiple indexes.Publisher<String>
createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.Publisher<DeleteResult>
deleteMany(ClientSession clientSession, Bson filter)
Removes all documents from the collection that match the given query filter.Publisher<DeleteResult>
deleteMany(ClientSession clientSession, Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter.Publisher<DeleteResult>
deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter.Publisher<DeleteResult>
deleteMany(Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter.Publisher<DeleteResult>
deleteOne(ClientSession clientSession, Bson filter)
Removes at most one document from the collection that matches the given filter.Publisher<DeleteResult>
deleteOne(ClientSession clientSession, Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter.Publisher<DeleteResult>
deleteOne(Bson filter)
Removes at most one document from the collection that matches the given filter.Publisher<DeleteResult>
deleteOne(Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter.<TResult> DistinctPublisher<TResult>
distinct(ClientSession clientSession, String fieldName, Class<TResult> resultClass)
Gets the distinct values of the specified field name.<TResult> DistinctPublisher<TResult>
distinct(ClientSession clientSession, String fieldName, 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.<TResult> DistinctPublisher<TResult>
distinct(String fieldName, Bson filter, Class<TResult> resultClass)
Gets the distinct values of the specified field name.Publisher<Void>
drop()
Drops this collection from the Database.Publisher<Void>
drop(ClientSession clientSession)
Drops this collection from the Database.Publisher<Void>
dropIndex(ClientSession clientSession, String indexName)
Drops the given index.Publisher<Void>
dropIndex(ClientSession clientSession, String indexName, DropIndexOptions dropIndexOptions)
Drops the given index.Publisher<Void>
dropIndex(ClientSession clientSession, Bson keys)
Drops the index given the keys used to create it.Publisher<Void>
dropIndex(ClientSession clientSession, Bson keys, DropIndexOptions dropIndexOptions)
Drops the index given the keys used to create it.Publisher<Void>
dropIndex(String indexName)
Drops the given index.Publisher<Void>
dropIndex(String indexName, DropIndexOptions dropIndexOptions)
Drops the given index.Publisher<Void>
dropIndex(Bson keys)
Drops the index given the keys used to create it.Publisher<Void>
dropIndex(Bson keys, DropIndexOptions dropIndexOptions)
Drops the index given the keys used to create it.Publisher<Void>
dropIndexes()
Drop all the indexes on this collection, except for the default on _id.Publisher<Void>
dropIndexes(DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.Publisher<Void>
dropIndexes(ClientSession clientSession)
Drop all the indexes on this collection, except for the default on _id.Publisher<Void>
dropIndexes(ClientSession clientSession, DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.Publisher<Long>
estimatedDocumentCount()
Gets an estimate of the count of documents in a collection using collection metadata.Publisher<Long>
estimatedDocumentCount(EstimatedDocumentCountOptions options)
Gets an estimate of the count of documents in a collection using collection metadata.FindPublisher<TDocument>
find()
Finds all documents in the collection.FindPublisher<TDocument>
find(ClientSession clientSession)
Finds all documents in the collection.<TResult> FindPublisher<TResult>
find(ClientSession clientSession, Class<TResult> clazz)
Finds all documents in the collection.FindPublisher<TDocument>
find(ClientSession clientSession, Bson filter)
Finds all documents in the collection.<TResult> FindPublisher<TResult>
find(ClientSession clientSession, Bson filter, Class<TResult> clazz)
Finds all documents in the collection.<TResult> FindPublisher<TResult>
find(Class<TResult> clazz)
Finds all documents in the collection.FindPublisher<TDocument>
find(Bson filter)
Finds all documents in the collection.<TResult> FindPublisher<TResult>
find(Bson filter, Class<TResult> clazz)
Finds all documents in the collection.Publisher<TDocument>
findOneAndDelete(ClientSession clientSession, Bson filter)
Atomically find a document and remove it.Publisher<TDocument>
findOneAndDelete(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.Publisher<TDocument>
findOneAndDelete(Bson filter)
Atomically find a document and remove it.Publisher<TDocument>
findOneAndDelete(Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.Publisher<TDocument>
findOneAndReplace(ClientSession clientSession, Bson filter, TDocument replacement)
Atomically find a document and replace it.Publisher<TDocument>
findOneAndReplace(ClientSession clientSession, Bson filter, TDocument replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.Publisher<TDocument>
findOneAndReplace(Bson filter, TDocument replacement)
Atomically find a document and replace it.Publisher<TDocument>
findOneAndReplace(Bson filter, TDocument replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.Publisher<TDocument>
findOneAndUpdate(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(ClientSession clientSession, Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(Bson filter, List<? extends Bson> update)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(Bson filter, Bson update)
Atomically find a document and update it.Publisher<TDocument>
findOneAndUpdate(Bson filter, Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.CodecRegistry
getCodecRegistry()
Get the codec registry for the MongoCollection.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.Publisher<InsertManyResult>
insertMany(ClientSession clientSession, List<? extends TDocument> documents)
Inserts a batch of documents.Publisher<InsertManyResult>
insertMany(ClientSession clientSession, List<? extends TDocument> documents, InsertManyOptions options)
Inserts a batch of documents.Publisher<InsertManyResult>
insertMany(List<? extends TDocument> documents)
Inserts a batch of documents.Publisher<InsertManyResult>
insertMany(List<? extends TDocument> documents, InsertManyOptions options)
Inserts a batch of documents.Publisher<InsertOneResult>
insertOne(ClientSession clientSession, TDocument document)
Inserts the provided document.Publisher<InsertOneResult>
insertOne(ClientSession clientSession, TDocument document, InsertOneOptions options)
Inserts the provided document.Publisher<InsertOneResult>
insertOne(TDocument document)
Inserts the provided document.Publisher<InsertOneResult>
insertOne(TDocument document, InsertOneOptions options)
Inserts the provided document.ListIndexesPublisher<Document>
listIndexes()
Get all the indexes in this collection.ListIndexesPublisher<Document>
listIndexes(ClientSession clientSession)
Get all the indexes in this collection.<TResult> ListIndexesPublisher<TResult>
listIndexes(ClientSession clientSession, Class<TResult> clazz)
Get all the indexes in this collection.<TResult> ListIndexesPublisher<TResult>
listIndexes(Class<TResult> clazz)
Get all the indexes in this collection.MapReducePublisher<TDocument>
mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction)
Aggregates documents according to the specified map-reduce function.<TResult> MapReducePublisher<TResult>
mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction, Class<TResult> clazz)
Aggregates documents according to the specified map-reduce function.MapReducePublisher<TDocument>
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.Publisher<Void>
renameCollection(MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.Publisher<Void>
renameCollection(MongoNamespace newCollectionNamespace, RenameCollectionOptions options)
Rename the collection with oldCollectionName to the newCollectionName.Publisher<Void>
renameCollection(ClientSession clientSession, MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.Publisher<Void>
renameCollection(ClientSession clientSession, MongoNamespace newCollectionNamespace, RenameCollectionOptions options)
Rename the collection with oldCollectionName to the newCollectionName.Publisher<UpdateResult>
replaceOne(ClientSession clientSession, Bson filter, TDocument replacement)
Replace a document in the collection according to the specified arguments.Publisher<UpdateResult>
replaceOne(ClientSession clientSession, Bson filter, TDocument replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.Publisher<UpdateResult>
replaceOne(Bson filter, TDocument replacement)
Replace a document in the collection according to the specified arguments.Publisher<UpdateResult>
replaceOne(Bson filter, TDocument replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(ClientSession clientSession, Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(Bson filter, List<? extends Bson> update)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(Bson filter, List<? extends Bson> update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateMany(Bson filter, Bson update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(ClientSession clientSession, Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(Bson filter, List<? extends Bson> update)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(Bson filter, List<? extends Bson> update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.Publisher<UpdateResult>
updateOne(Bson filter, Bson update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.ChangeStreamPublisher<Document>
watch()
Creates a change stream for this collection.ChangeStreamPublisher<Document>
watch(ClientSession clientSession)
Creates a change stream for this collection.<TResult> ChangeStreamPublisher<TResult>
watch(ClientSession clientSession, Class<TResult> resultClass)
Creates a change stream for this collection.ChangeStreamPublisher<Document>
watch(ClientSession clientSession, List<? extends Bson> pipeline)
Creates a change stream for this collection.<TResult> ChangeStreamPublisher<TResult>
watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass)
Creates a change stream for this collection.<TResult> ChangeStreamPublisher<TResult>
watch(Class<TResult> resultClass)
Creates a change stream for this collection.ChangeStreamPublisher<Document>
watch(List<? extends Bson> pipeline)
Creates a change stream for this collection.<TResult> ChangeStreamPublisher<TResult>
watch(List<? extends Bson> pipeline, Class<TResult> resultClass)
Creates a change stream for this collection.MongoCollection<TDocument>
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoCollection instance with a different codec registry.<NewTDocument>
MongoCollection<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>
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.
-
-
-
Method Detail
-
getNamespace
MongoNamespace getNamespace()
Gets the namespace of this collection.- Returns:
- the namespace
-
getDocumentClass
Class<TDocument> getDocumentClass()
Get the class of documents stored in this collection.- Returns:
- the class
-
getCodecRegistry
CodecRegistry getCodecRegistry()
Get the codec registry for the MongoCollection.- Returns:
- the
CodecRegistry
-
getReadPreference
ReadPreference getReadPreference()
Get the read preference for the MongoCollection.- Returns:
- the
ReadPreference
-
getWriteConcern
WriteConcern getWriteConcern()
Get the write concern for the MongoCollection.- Returns:
- the
WriteConcern
-
getReadConcern
ReadConcern getReadConcern()
Get the read concern for the MongoCollection.- Returns:
- the
ReadConcern
- Since:
- 1.2
- Since server release
- 3.2
-
withDocumentClass
<NewTDocument> MongoCollection<NewTDocument> withDocumentClass(Class<NewTDocument> clazz)
Create a new MongoCollection instance with a different default class to cast any documents returned from the database into..- Type Parameters:
NewTDocument
- The type that the new collection will encode documents from and decode documents to- Parameters:
clazz
- the default class to cast any documents returned from the database into.- Returns:
- a new MongoCollection instance with the different default class
-
withCodecRegistry
MongoCollection<TDocument> withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoCollection instance with a different codec registry.- Parameters:
codecRegistry
- the newCodecRegistry
for the collection- Returns:
- a new MongoCollection instance with the different codec registry
-
withReadPreference
MongoCollection<TDocument> withReadPreference(ReadPreference readPreference)
Create a new MongoCollection instance with a different read preference.- Parameters:
readPreference
- the newReadPreference
for the collection- Returns:
- a new MongoCollection instance with the different readPreference
-
withWriteConcern
MongoCollection<TDocument> withWriteConcern(WriteConcern writeConcern)
Create a new MongoCollection instance with a different write concern.- Parameters:
writeConcern
- the newWriteConcern
for the collection- Returns:
- a new MongoCollection instance with the different writeConcern
-
withReadConcern
MongoCollection<TDocument> withReadConcern(ReadConcern readConcern)
Create a new MongoCollection instance with a different read concern.- Parameters:
readConcern
- the newReadConcern
for the collection- Returns:
- a new MongoCollection instance with the different ReadConcern
- Since:
- 1.2
- Since server release
- 3.2
-
estimatedDocumentCount
Publisher<Long> estimatedDocumentCount()
Gets an estimate of the count of documents in a collection using collection metadata.- Returns:
- a publisher with a single element indicating the estimated number of documents
- Since:
- 1.9
-
estimatedDocumentCount
Publisher<Long> estimatedDocumentCount(EstimatedDocumentCountOptions options)
Gets an estimate of the count of documents in a collection using collection metadata.- Parameters:
options
- the options describing the count- Returns:
- a publisher with a single element indicating the estimated number of documents
- Since:
- 1.9
-
countDocuments
Publisher<Long> countDocuments()
Counts the number of documents in the collection.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.
Note: When migrating fromcount()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
-
countDocuments
Publisher<Long> countDocuments(Bson filter)
Counts the number of documents in the collection according to the given options.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.
Note: When migrating fromcount()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Parameters:
filter
- the query filter- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
-
countDocuments
Publisher<Long> countDocuments(Bson filter, CountOptions options)
Counts the number of documents in the collection according to the given options.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.
Note: When migrating fromcount()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Parameters:
filter
- the query filteroptions
- the options describing the count- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
-
countDocuments
Publisher<Long> countDocuments(ClientSession clientSession)
Counts the number of documents in the collection.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.
Note: When migrating fromcount()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
- Since server release
- 3.6
-
countDocuments
Publisher<Long> countDocuments(ClientSession clientSession, Bson filter)
Counts the number of documents in the collection according to the given options.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
- Since server release
- 3.6
-
countDocuments
Publisher<Long> countDocuments(ClientSession clientSession, Bson filter, CountOptions options)
Counts the number of documents in the collection according to the given options.Note: For a fast count of the total documents in a collection see
estimatedDocumentCount()
.
Note: When migrating fromcount()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filteroptions
- the options describing the count- Returns:
- a publisher with a single element indicating the number of documents
- Since:
- 1.9
- Since server release
- 3.6
-
distinct
<TResult> DistinctPublisher<TResult> distinct(String fieldName, Class<TResult> resultClass)
Gets the distinct values of the specified field name.- Type Parameters:
TResult
- the target type of the iterable.- Parameters:
fieldName
- the field nameresultClass
- the default class to cast any distinct items into.- Returns:
- a publisher emitting the sequence of distinct values
- MongoDB documentation
- Distinct
-
distinct
<TResult> DistinctPublisher<TResult> distinct(String fieldName, Bson filter, Class<TResult> resultClass)
Gets the distinct values of the specified field name.- Type Parameters:
TResult
- the target type of the iterable.- Parameters:
fieldName
- the field namefilter
- the query filterresultClass
- the default class to cast any distinct items into.- Returns:
- an iterable of distinct values
- MongoDB documentation
- Distinct
-
distinct
<TResult> DistinctPublisher<TResult> distinct(ClientSession clientSession, String fieldName, Class<TResult> resultClass)
Gets the distinct values of the specified field name.- Type Parameters:
TResult
- the target type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationfieldName
- the field nameresultClass
- the default class to cast any distinct items into.- Returns:
- a publisher emitting the sequence of distinct values
- Since:
- 1.7
-
distinct
<TResult> DistinctPublisher<TResult> distinct(ClientSession clientSession, String fieldName, Bson filter, Class<TResult> resultClass)
Gets the distinct values of the specified field name.- Type Parameters:
TResult
- the target type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationfieldName
- the field namefilter
- the query filterresultClass
- the default class to cast any distinct items into.- Returns:
- an iterable of distinct values
- Since:
- 1.7
-
find
FindPublisher<TDocument> find()
Finds all documents in the collection.- Returns:
- the fluent find interface
- MongoDB documentation
- Find
-
find
<TResult> FindPublisher<TResult> find(Class<TResult> clazz)
Finds all documents in the collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clazz
- the class to decode each document into- Returns:
- the fluent find interface
- MongoDB documentation
- Find
-
find
FindPublisher<TDocument> find(Bson filter)
Finds all documents in the collection.- Parameters:
filter
- the query filter- Returns:
- the fluent find interface
- MongoDB documentation
- Find
-
find
<TResult> FindPublisher<TResult> find(Bson filter, Class<TResult> clazz)
Finds all documents in the collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
filter
- the query filterclazz
- the class to decode each document into- Returns:
- the fluent find interface
- MongoDB documentation
- Find
-
find
FindPublisher<TDocument> find(ClientSession clientSession)
Finds all documents in the collection.
-
find
<TResult> FindPublisher<TResult> find(ClientSession clientSession, Class<TResult> clazz)
Finds all documents in the collection.
-
find
FindPublisher<TDocument> find(ClientSession clientSession, Bson filter)
Finds all documents in the collection.
-
find
<TResult> FindPublisher<TResult> find(ClientSession clientSession, Bson filter, Class<TResult> clazz)
Finds all documents in the collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filterclazz
- the class to decode each document into- Returns:
- the fluent find interface
- Since:
- 1.7
-
aggregate
AggregatePublisher<TDocument> aggregate(List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.- Parameters:
pipeline
- the aggregate pipeline- Returns:
- a publisher containing the result of the aggregation operation
- MongoDB documentation
- Aggregation
-
aggregate
<TResult> AggregatePublisher<TResult> aggregate(List<? extends Bson> pipeline, Class<TResult> clazz)
Aggregates documents according to the specified aggregation pipeline.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
pipeline
- the aggregate pipelineclazz
- the class to decode each document into- Returns:
- a publisher containing the result of the aggregation operation
- MongoDB documentation
- Aggregation
-
aggregate
AggregatePublisher<TDocument> aggregate(ClientSession clientSession, List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.- Parameters:
clientSession
- the client session with which to associate this operationpipeline
- the aggregate pipeline- Returns:
- a publisher containing the result of the aggregation operation
- Since:
- 1.7
- MongoDB documentation
- Aggregation
- Since server release
- 3.6
-
aggregate
<TResult> AggregatePublisher<TResult> aggregate(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> clazz)
Aggregates documents according to the specified aggregation pipeline.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationpipeline
- the aggregate pipelineclazz
- the class to decode each document into- Returns:
- a publisher containing the result of the aggregation operation
- Since:
- 1.7
- MongoDB documentation
- Aggregation
- Since server release
- 3.6
-
watch
ChangeStreamPublisher<Document> watch()
Creates a change stream for this collection.- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
watch
<TResult> ChangeStreamPublisher<TResult> watch(Class<TResult> resultClass)
Creates a change stream for this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
resultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
watch
ChangeStreamPublisher<Document> watch(List<? extends Bson> pipeline)
Creates a change stream for this collection.- Parameters:
pipeline
- the aggregation pipeline to apply to the change stream- Returns:
- the change stream iterable
- Since:
- 1.6
- MongoDB documentation
- $changeStream
-
watch
<TResult> ChangeStreamPublisher<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass)
Creates a change stream for this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
pipeline
- the aggregation pipeline to apply to the change streamresultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 1.6
- MongoDB documentation
- $changeStream
-
watch
ChangeStreamPublisher<Document> watch(ClientSession clientSession)
Creates a change stream for this collection.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
watch
<TResult> ChangeStreamPublisher<TResult> watch(ClientSession clientSession, Class<TResult> resultClass)
Creates a change stream for this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationresultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
watch
ChangeStreamPublisher<Document> watch(ClientSession clientSession, List<? extends Bson> pipeline)
Creates a change stream for this collection.- Parameters:
clientSession
- the client session with which to associate this operationpipeline
- the aggregation pipeline to apply to the change stream- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
watch
<TResult> ChangeStreamPublisher<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass)
Creates a change stream for this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationpipeline
- the aggregation pipeline to apply to the change streamresultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 1.7
- MongoDB documentation
- $changeStream
- Since server release
- 3.6
-
mapReduce
MapReducePublisher<TDocument> mapReduce(String mapFunction, String reduceFunction)
Aggregates documents according to the specified map-reduce function.- Parameters:
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.- Returns:
- an publisher containing the result of the map-reduce operation
- MongoDB documentation
- map-reduce
-
mapReduce
<TResult> MapReducePublisher<TResult> mapReduce(String mapFunction, String reduceFunction, Class<TResult> clazz)
Aggregates documents according to the specified map-reduce function.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
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.- Returns:
- a publisher containing the result of the map-reduce operation
- MongoDB documentation
- map-reduce
-
mapReduce
MapReducePublisher<TDocument> mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction)
Aggregates documents according to the specified map-reduce function.- Parameters:
clientSession
- the client session with which to associate this operationmapFunction
- 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.- Returns:
- an publisher containing the result of the map-reduce operation
- Since:
- 1.7
- MongoDB documentation
- map-reduce
- Since server release
- 3.6
-
mapReduce
<TResult> MapReducePublisher<TResult> mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction, Class<TResult> clazz)
Aggregates documents according to the specified map-reduce function.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationmapFunction
- 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.- Returns:
- a publisher containing the result of the map-reduce operation
- Since:
- 1.7
- MongoDB documentation
- map-reduce
- Since server release
- 3.6
-
bulkWrite
Publisher<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.- Parameters:
requests
- the writes to execute- Returns:
- a publisher with a single element the BulkWriteResult
-
bulkWrite
Publisher<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.- Parameters:
requests
- the writes to executeoptions
- the options to apply to the bulk write operation- Returns:
- a publisher with a single element the BulkWriteResult
-
bulkWrite
Publisher<BulkWriteResult> bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests)
Executes a mix of inserts, updates, replaces, and deletes.- Parameters:
clientSession
- the client session with which to associate this operationrequests
- the writes to execute- Returns:
- a publisher with a single element the BulkWriteResult
- Since:
- 1.7
- Since server release
- 3.6
-
bulkWrite
Publisher<BulkWriteResult> bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.- Parameters:
clientSession
- the client session with which to associate this operationrequests
- the writes to executeoptions
- the options to apply to the bulk write operation- Returns:
- a publisher with a single element the BulkWriteResult
- Since:
- 1.7
- Since server release
- 3.6
-
insertOne
Publisher<InsertOneResult> insertOne(TDocument document)
Inserts the provided document. If the document is missing an identifier, the driver should generate one.- Parameters:
document
- the document to insert- Returns:
- a publisher with a single element with the InsertOneResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
-
insertOne
Publisher<InsertOneResult> insertOne(TDocument document, InsertOneOptions options)
Inserts the provided document. If the document is missing an identifier, the driver should generate one.- Parameters:
document
- the document to insertoptions
- the options to apply to the operation- Returns:
- a publisher with a single element with the InsertOneResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
- Since:
- 1.2
-
insertOne
Publisher<InsertOneResult> insertOne(ClientSession clientSession, TDocument document)
Inserts the provided document. If the document is missing an identifier, the driver should generate one.- Parameters:
clientSession
- the client session with which to associate this operationdocument
- the document to insert- Returns:
- a publisher with a single element with the InsertOneResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
insertOne
Publisher<InsertOneResult> insertOne(ClientSession clientSession, TDocument document, InsertOneOptions options)
Inserts the provided document. If the document is missing an identifier, the driver should generate one.- Parameters:
clientSession
- the client session with which to associate this operationdocument
- the document to insertoptions
- the options to apply to the operation- Returns:
- a publisher with a single element with the InsertOneResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
insertMany
Publisher<InsertManyResult> insertMany(List<? extends TDocument> documents)
Inserts a batch of documents.- Parameters:
documents
- the documents to insert- Returns:
- a publisher with a single element with the InsertManyResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
-
insertMany
Publisher<InsertManyResult> insertMany(List<? extends TDocument> documents, InsertManyOptions options)
Inserts a batch of documents.- Parameters:
documents
- the documents to insertoptions
- the options to apply to the operation- Returns:
- a publisher with a single element with the InsertManyResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
-
insertMany
Publisher<InsertManyResult> insertMany(ClientSession clientSession, List<? extends TDocument> documents)
Inserts a batch of documents.- Parameters:
clientSession
- the client session with which to associate this operationdocuments
- the documents to insert- Returns:
- a publisher with a single element with the InsertManyResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
insertMany
Publisher<InsertManyResult> insertMany(ClientSession clientSession, List<? extends TDocument> documents, InsertManyOptions options)
Inserts a batch of documents.- Parameters:
clientSession
- the client session with which to associate this operationdocuments
- the documents to insertoptions
- the options to apply to the operation- Returns:
- a publisher with a single element with the InsertManyResult or with either a com.mongodb.DuplicateKeyException or com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
deleteOne
Publisher<DeleteResult> deleteOne(Bson filter)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
-
deleteOne
Publisher<DeleteResult> deleteOne(Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.5
-
deleteOne
Publisher<DeleteResult> deleteOne(ClientSession clientSession, Bson filter)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
deleteOne
Publisher<DeleteResult> deleteOne(ClientSession clientSession, Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
deleteMany
Publisher<DeleteResult> deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
-
deleteMany
Publisher<DeleteResult> deleteMany(Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.5
-
deleteMany
Publisher<DeleteResult> deleteMany(ClientSession clientSession, Bson filter)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
deleteMany
Publisher<DeleteResult> deleteMany(ClientSession clientSession, Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
- Since:
- 1.7
- Since server release
- 3.6
-
replaceOne
Publisher<UpdateResult> replaceOne(Bson filter, TDocument replacement)
Replace a document in the collection according to the specified arguments.- Parameters:
filter
- the query filter to apply the the replace operationreplacement
- the replacement document- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Replace
-
replaceOne
Publisher<UpdateResult> replaceOne(Bson filter, TDocument replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.- Parameters:
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the replace operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.8
- MongoDB documentation
- Replace
-
replaceOne
Publisher<UpdateResult> replaceOne(ClientSession clientSession, Bson filter, TDocument replacement)
Replace a document in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the replace operationreplacement
- the replacement document- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.7
-
replaceOne
Publisher<UpdateResult> replaceOne(ClientSession clientSession, Bson filter, TDocument replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the replace operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.8
-
updateOne
Publisher<UpdateResult> updateOne(Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.- Parameters:
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.- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Updates
- Update Operators
-
updateOne
Publisher<UpdateResult> updateOne(Bson filter, Bson update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.- Parameters:
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 operation- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Updates
- Update Operators
-
updateOne
Publisher<UpdateResult> updateOne(ClientSession clientSession, Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.7
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 3.6
-
updateOne
Publisher<UpdateResult> updateOne(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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 operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.7
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 3.6
-
updateOne
Publisher<UpdateResult> updateOne(Bson filter, List<? extends Bson> update)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateOne
Publisher<UpdateResult> updateOne(Bson filter, List<? extends Bson> update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the update operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateOne
Publisher<UpdateResult> updateOne(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateOne
Publisher<UpdateResult> updateOne(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the update operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateMany
Publisher<UpdateResult> updateMany(Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.- Parameters:
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.- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Updates
- Update Operators
-
updateMany
Publisher<UpdateResult> updateMany(Bson filter, Bson update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.- Parameters:
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 operation- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Updates
- Update Operators
-
updateMany
Publisher<UpdateResult> updateMany(ClientSession clientSession, Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.7
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 3.6
-
updateMany
Publisher<UpdateResult> updateMany(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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 operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.7
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 3.6
-
updateMany
Publisher<UpdateResult> updateMany(Bson filter, List<? extends Bson> update)
Update all documents in the collection according to the specified arguments.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateMany
Publisher<UpdateResult> updateMany(Bson filter, List<? extends Bson> update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the update operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateMany
Publisher<UpdateResult> updateMany(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Update all documents in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
updateMany
Publisher<UpdateResult> updateMany(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options)
Update all documents in the collection according to the specified arguments.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the update operation- Returns:
- a publisher with a single element the UpdateResult
- Since:
- 1.12
- MongoDB documentation
- Updates
- Update Operators
- Since server release
- 4.2
-
findOneAndDelete
Publisher<TDocument> findOneAndDelete(Bson filter)
Atomically find a document and remove it.- Parameters:
filter
- the query filter to find the document with- Returns:
- a publisher with a single element the document that was removed. If no documents matched the query filter, then null will be returned
-
findOneAndDelete
Publisher<TDocument> findOneAndDelete(Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.- Parameters:
filter
- the query filter to find the document withoptions
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was removed. If no documents matched the query filter, then null will be returned
-
findOneAndDelete
Publisher<TDocument> findOneAndDelete(ClientSession clientSession, Bson filter)
Atomically find a document and remove it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to find the document with- Returns:
- a publisher with a single element the document that was removed. If no documents matched the query filter, then null will be returned
- Since:
- 1.7
- Since server release
- 3.6
-
findOneAndDelete
Publisher<TDocument> findOneAndDelete(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to find the document withoptions
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was removed. If no documents matched the query filter, then null will be returned
- Since:
- 1.7
- Since server release
- 3.6
-
findOneAndReplace
Publisher<TDocument> findOneAndReplace(Bson filter, TDocument replacement)
Atomically find a document and replace it.- Parameters:
filter
- the query filter to apply the the replace operationreplacement
- the replacement document- Returns:
- a publisher with a single element the document that was replaced. Depending on the value of the
returnOriginal
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 returned
-
findOneAndReplace
Publisher<TDocument> findOneAndReplace(Bson filter, TDocument replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.- Parameters:
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was replaced. Depending on the value of the
returnOriginal
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 returned
-
findOneAndReplace
Publisher<TDocument> findOneAndReplace(ClientSession clientSession, Bson filter, TDocument replacement)
Atomically find a document and replace it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the replace operationreplacement
- the replacement document- Returns:
- a publisher with a single element the document that was replaced. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.7
- Since server release
- 3.6
-
findOneAndReplace
Publisher<TDocument> findOneAndReplace(ClientSession clientSession, Bson filter, TDocument replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was replaced. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.7
- Since server release
- 3.6
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(Bson filter, Bson update)
Atomically find a document and update it.- Parameters:
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.- Returns:
- a publisher with a single element the document that was updated before the update was applied. If no documents matched the query filter, then null will be returned
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(Bson filter, Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.- Parameters:
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 operation- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update)
Atomically find a document and update it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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.- Returns:
- a publisher with a single element the document that was updated before the update was applied. If no documents matched the query filter, then null will be returned
- Since:
- 1.7
- Since server release
- 3.6
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.- Parameters:
clientSession
- the client session with which to associate this operationfilter
- 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 operation- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.7
- Since server release
- 3.6
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(Bson filter, List<? extends Bson> update)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.12
- Since server release
- 4.2
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.12
- Since server release
- 4.2
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(ClientSession clientSession, Bson filter, List<? extends Bson> update)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.12
- Since server release
- 4.2
-
findOneAndUpdate
Publisher<TDocument> findOneAndUpdate(ClientSession clientSession, Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
clientSession
- the client session with which to associate this operationfilter
- a document describing the query filter, which may not be null.update
- a pipeline describing the update, which may not be null.options
- the options to apply to the operation- Returns:
- a publisher with a single element the document that was updated. Depending on the value of the
returnOriginal
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 returned - Since:
- 1.12
- Since server release
- 4.2
-
drop
Publisher<Void> drop()
Drops this collection from the Database.- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Drop Collection
-
drop
Publisher<Void> drop(ClientSession clientSession)
Drops this collection from the Database.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Collection
- Since server release
- 3.6
-
createIndex
Publisher<String> createIndex(Bson key)
Creates an index.- Parameters:
key
- an object describing the index key(s), which may not be null.- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Ensure Index
-
createIndex
Publisher<String> createIndex(Bson key, IndexOptions options)
Creates an index.- Parameters:
key
- an object describing the index key(s), which may not be null.options
- the options for the index- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Ensure Index
-
createIndex
Publisher<String> createIndex(ClientSession clientSession, Bson key)
Creates an index.- Parameters:
clientSession
- the client session with which to associate this operationkey
- an object describing the index key(s), which may not be null.- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Ensure Index
- Since server release
- 3.6
-
createIndex
Publisher<String> createIndex(ClientSession clientSession, Bson key, IndexOptions options)
Creates an index.- Parameters:
clientSession
- the client session with which to associate this operationkey
- an object describing the index key(s), which may not be null.options
- the options for the index- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Ensure Index
- Since server release
- 3.6
-
createIndexes
Publisher<String> createIndexes(List<IndexModel> indexes)
Create multiple indexes.- Parameters:
indexes
- the list of indexes- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Create indexes
-
createIndexes
Publisher<String> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.- Parameters:
indexes
- the list of indexescreateIndexOptions
- options to use when creating indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Create indexes
-
createIndexes
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes)
Create multiple indexes.- Parameters:
clientSession
- the client session with which to associate this operationindexes
- the list of indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Create indexes
- Since server release
- 3.6
-
createIndexes
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.- Parameters:
clientSession
- the client session with which to associate this operationindexes
- the list of indexescreateIndexOptions
- options to use when creating indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Create indexes
- Since server release
- 3.6
-
listIndexes
ListIndexesPublisher<Document> listIndexes()
Get all the indexes in this collection.- Returns:
- the fluent list indexes interface
- MongoDB documentation
- listIndexes
-
listIndexes
<TResult> ListIndexesPublisher<TResult> listIndexes(Class<TResult> clazz)
Get all the indexes in this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clazz
- the class to decode each document into- Returns:
- the fluent list indexes interface
- MongoDB documentation
- listIndexes
-
listIndexes
ListIndexesPublisher<Document> listIndexes(ClientSession clientSession)
Get all the indexes in this collection.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- the fluent list indexes interface
- Since:
- 1.7
- MongoDB documentation
- listIndexes
- Since server release
- 3.6
-
listIndexes
<TResult> ListIndexesPublisher<TResult> listIndexes(ClientSession clientSession, Class<TResult> clazz)
Get all the indexes in this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationclazz
- the class to decode each document into- Returns:
- the fluent list indexes interface
- Since:
- 1.7
- MongoDB documentation
- listIndexes
- Since server release
- 3.6
-
dropIndex
Publisher<Void> dropIndex(String indexName)
Drops the given index.- Parameters:
indexName
- the name of the index to remove- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Drop Indexes
-
dropIndex
Publisher<Void> dropIndex(Bson keys)
Drops the index given the keys used to create it.- Parameters:
keys
- the keys of the index to remove- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Drop indexes
-
dropIndex
Publisher<Void> dropIndex(String indexName, DropIndexOptions dropIndexOptions)
Drops the given index.- Parameters:
indexName
- the name of the index to removedropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
-
dropIndex
Publisher<Void> dropIndex(Bson keys, DropIndexOptions dropIndexOptions)
Drops the index given the keys used to create it.- Parameters:
keys
- the keys of the index to removedropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop indexes
-
dropIndex
Publisher<Void> dropIndex(ClientSession clientSession, String indexName)
Drops the given index.- Parameters:
clientSession
- the client session with which to associate this operationindexName
- the name of the index to remove- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
- Since server release
- 3.6
-
dropIndex
Publisher<Void> dropIndex(ClientSession clientSession, Bson keys)
Drops the index given the keys used to create it.- Parameters:
clientSession
- the client session with which to associate this operationkeys
- the keys of the index to remove- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop indexes
- Since server release
- 3.6
-
dropIndex
Publisher<Void> dropIndex(ClientSession clientSession, String indexName, DropIndexOptions dropIndexOptions)
Drops the given index.- Parameters:
clientSession
- the client session with which to associate this operationindexName
- the name of the index to removedropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
- Since server release
- 3.6
-
dropIndex
Publisher<Void> dropIndex(ClientSession clientSession, Bson keys, DropIndexOptions dropIndexOptions)
Drops the index given the keys used to create it.- Parameters:
clientSession
- the client session with which to associate this operationkeys
- the keys of the index to removedropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop indexes
- Since server release
- 3.6
-
dropIndexes
Publisher<Void> dropIndexes()
Drop all the indexes on this collection, except for the default on _id.- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Drop Indexes
-
dropIndexes
Publisher<Void> dropIndexes(DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.- Parameters:
dropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
-
dropIndexes
Publisher<Void> dropIndexes(ClientSession clientSession)
Drop all the indexes on this collection, except for the default on _id.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
- Since server release
- 3.6
-
dropIndexes
Publisher<Void> dropIndexes(ClientSession clientSession, DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.- Parameters:
clientSession
- the client session with which to associate this operationdropIndexOptions
- options to use when dropping indexes- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Drop Indexes
- Since server release
- 3.6
-
renameCollection
Publisher<Void> renameCollection(MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.- Parameters:
newCollectionNamespace
- the namespace the collection will be renamed to- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Rename collection
-
renameCollection
Publisher<Void> renameCollection(MongoNamespace newCollectionNamespace, RenameCollectionOptions options)
Rename the collection with oldCollectionName to the newCollectionName.- Parameters:
newCollectionNamespace
- the name the collection will be renamed tooptions
- the options for renaming a collection- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Rename collection
-
renameCollection
Publisher<Void> renameCollection(ClientSession clientSession, MongoNamespace newCollectionNamespace)
Rename the collection with oldCollectionName to the newCollectionName.- Parameters:
clientSession
- the client session with which to associate this operationnewCollectionNamespace
- the namespace the collection will be renamed to- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Rename collection
- Since server release
- 3.6
-
renameCollection
Publisher<Void> renameCollection(ClientSession clientSession, MongoNamespace newCollectionNamespace, RenameCollectionOptions options)
Rename the collection with oldCollectionName to the newCollectionName.- Parameters:
clientSession
- the client session with which to associate this operationnewCollectionNamespace
- the name the collection will be renamed tooptions
- the options for renaming a collection- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 1.7
- MongoDB documentation
- Rename collection
- Since server release
- 3.6
-
-