Interface MongoCollection<TDocument>
- Type Parameters:
TDocument
- The type that this collection will encode documents from and decode documents to.
Note: Additions to this interface will not be considered to break binary compatibility.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionaggregate
(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.Aggregates documents according to the specified aggregation pipeline.<TResult> AggregatePublisher<TResult>
Aggregates documents according to the specified aggregation pipeline.bulkWrite
(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests) Executes a mix of inserts, updates, replaces, and deletes.bulkWrite
(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options) Executes a mix of inserts, updates, replaces, and deletes.bulkWrite
(List<? extends WriteModel<? extends TDocument>> requests) Executes a mix of inserts, updates, replaces, and deletes.bulkWrite
(List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options) Executes a mix of inserts, updates, replaces, and deletes.Counts the number of documents in the collection.countDocuments
(ClientSession clientSession) Counts the number of documents in the collection.countDocuments
(ClientSession clientSession, Bson filter) Counts the number of documents in the collection according to the given options.countDocuments
(ClientSession clientSession, Bson filter, CountOptions options) Counts the number of documents in the collection according to the given options.countDocuments
(Bson filter) Counts the number of documents in the collection according to the given options.countDocuments
(Bson filter, CountOptions options) Counts the number of documents in the collection according to the given options.createIndex
(ClientSession clientSession, Bson key) Creates an index.createIndex
(ClientSession clientSession, Bson key, IndexOptions options) Creates an index.createIndex
(Bson key) Creates an index.createIndex
(Bson key, IndexOptions options) Creates an index.createIndexes
(ClientSession clientSession, List<IndexModel> indexes) Create multiple indexes.createIndexes
(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions) Create multiple indexes.createIndexes
(List<IndexModel> indexes) Create multiple indexes.createIndexes
(List<IndexModel> indexes, CreateIndexOptions createIndexOptions) Create multiple indexes.createSearchIndex
(String indexName, Bson definition) Create an Atlas Search index for the collection.createSearchIndex
(Bson definition) Create an Atlas Search index with"default"
name for the collection.createSearchIndexes
(List<SearchIndexModel> searchIndexModels) Create one or more Atlas Search indexes for the collection.deleteMany
(ClientSession clientSession, Bson filter) Removes all documents from the collection that match the given query filter.deleteMany
(ClientSession clientSession, Bson filter, DeleteOptions options) Removes all documents from the collection that match the given query filter.deleteMany
(Bson filter) Removes all documents from the collection that match the given query filter.deleteMany
(Bson filter, DeleteOptions options) Removes all documents from the collection that match the given query filter.deleteOne
(ClientSession clientSession, Bson filter) Removes at most one document from the collection that matches the given filter.deleteOne
(ClientSession clientSession, Bson filter, DeleteOptions options) Removes at most one document from the collection that matches the given filter.Removes at most one document from the collection that matches the given filter.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>
Gets the distinct values of the specified field name.<TResult> DistinctPublisher<TResult>
Gets the distinct values of the specified field name.drop()
Drops this collection from the Database.drop
(DropCollectionOptions dropCollectionOptions) Drops this collection from the Database.drop
(ClientSession clientSession) Drops this collection from the Database.drop
(ClientSession clientSession, DropCollectionOptions dropCollectionOptions) Drops this collection from the Database.dropIndex
(ClientSession clientSession, String indexName) Drops the given index.dropIndex
(ClientSession clientSession, String indexName, DropIndexOptions dropIndexOptions) Drops the given index.dropIndex
(ClientSession clientSession, Bson keys) Drops the index given the keys used to create it.dropIndex
(ClientSession clientSession, Bson keys, DropIndexOptions dropIndexOptions) Drops the index given the keys used to create it.Drops the given index.dropIndex
(String indexName, DropIndexOptions dropIndexOptions) Drops the given index.Drops the index given the keys used to create it.dropIndex
(Bson keys, DropIndexOptions dropIndexOptions) Drops the index given the keys used to create it.Drop all the indexes on this collection, except for the default on _id.dropIndexes
(DropIndexOptions dropIndexOptions) Drop all the indexes on this collection, except for the default on _id.dropIndexes
(ClientSession clientSession) Drop all the indexes on this collection, except for the default on _id.dropIndexes
(ClientSession clientSession, DropIndexOptions dropIndexOptions) Drop all the indexes on this collection, except for the default on _id.dropSearchIndex
(String indexName) Drop an Atlas Search index given its name.Gets an estimate of the count of documents in a collection using collection metadata.Gets an estimate of the count of documents in a collection using collection metadata.find()
Finds all documents in the collection.find
(ClientSession clientSession) Finds all documents in the collection.<TResult> FindPublisher<TResult>
find
(ClientSession clientSession, Class<TResult> clazz) Finds all documents in the collection.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>
Finds all documents in the collection.Finds all documents in the collection.<TResult> FindPublisher<TResult>
Finds all documents in the collection.findOneAndDelete
(ClientSession clientSession, Bson filter) Atomically find a document and remove it.findOneAndDelete
(ClientSession clientSession, Bson filter, FindOneAndDeleteOptions options) Atomically find a document and remove it.findOneAndDelete
(Bson filter) Atomically find a document and remove it.findOneAndDelete
(Bson filter, FindOneAndDeleteOptions options) Atomically find a document and remove it.findOneAndReplace
(ClientSession clientSession, Bson filter, TDocument replacement) Atomically find a document and replace it.findOneAndReplace
(ClientSession clientSession, Bson filter, TDocument replacement, FindOneAndReplaceOptions options) Atomically find a document and replace it.findOneAndReplace
(Bson filter, TDocument replacement) Atomically find a document and replace it.findOneAndReplace
(Bson filter, TDocument replacement, FindOneAndReplaceOptions options) Atomically find a document and replace it.findOneAndUpdate
(ClientSession clientSession, Bson filter, List<? extends Bson> update) Atomically find a document and update it.findOneAndUpdate
(ClientSession clientSession, Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options) Atomically find a document and update it.findOneAndUpdate
(ClientSession clientSession, Bson filter, Bson update) Atomically find a document and update it.findOneAndUpdate
(ClientSession clientSession, Bson filter, Bson update, FindOneAndUpdateOptions options) Atomically find a document and update it.findOneAndUpdate
(Bson filter, List<? extends Bson> update) Atomically find a document and update it.findOneAndUpdate
(Bson filter, List<? extends Bson> update, FindOneAndUpdateOptions options) Atomically find a document and update it.findOneAndUpdate
(Bson filter, Bson update) Atomically find a document and update it.findOneAndUpdate
(Bson filter, Bson update, FindOneAndUpdateOptions options) Atomically find a document and update it.Get the codec registry for the MongoCollection.Get the class of documents stored in this collection.Gets the namespace of this collection.Get the read concern for the MongoCollection.Get the read preference for the MongoCollection.Get the write concern for the MongoCollection.insertMany
(ClientSession clientSession, List<? extends TDocument> documents) Inserts a batch of documents.insertMany
(ClientSession clientSession, List<? extends TDocument> documents, InsertManyOptions options) Inserts a batch of documents.insertMany
(List<? extends TDocument> documents) Inserts a batch of documents.insertMany
(List<? extends TDocument> documents, InsertManyOptions options) Inserts a batch of documents.insertOne
(ClientSession clientSession, TDocument document) Inserts the provided document.insertOne
(ClientSession clientSession, TDocument document, InsertOneOptions options) Inserts the provided document.Inserts the provided document.insertOne
(TDocument document, InsertOneOptions options) Inserts the provided document.Get all the indexes in this collection.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.Get all Atlas Search indexes in this collection.<TResult> ListSearchIndexesPublisher<TResult>
listSearchIndexes
(Class<TResult> resultClass) Get all Atlas Search indexes in this collection.mapReduce
(ClientSession clientSession, String mapFunction, String reduceFunction) Deprecated.Superseded by aggregate<TResult> MapReducePublisher<TResult>
mapReduce
(ClientSession clientSession, String mapFunction, String reduceFunction, Class<TResult> clazz) Deprecated.Superseded by aggregateDeprecated.Superseded by aggregate<TResult> MapReducePublisher<TResult>
Deprecated.Superseded by aggregaterenameCollection
(MongoNamespace newCollectionNamespace) Rename the collection with oldCollectionName to the newCollectionName.renameCollection
(MongoNamespace newCollectionNamespace, RenameCollectionOptions options) Rename the collection with oldCollectionName to the newCollectionName.renameCollection
(ClientSession clientSession, MongoNamespace newCollectionNamespace) Rename the collection with oldCollectionName to the newCollectionName.renameCollection
(ClientSession clientSession, MongoNamespace newCollectionNamespace, RenameCollectionOptions options) Rename the collection with oldCollectionName to the newCollectionName.replaceOne
(ClientSession clientSession, Bson filter, TDocument replacement) Replace a document in the collection according to the specified arguments.replaceOne
(ClientSession clientSession, Bson filter, TDocument replacement, ReplaceOptions options) Replace a document in the collection according to the specified arguments.replaceOne
(Bson filter, TDocument replacement) Replace a document in the collection according to the specified arguments.replaceOne
(Bson filter, TDocument replacement, ReplaceOptions options) Replace a document in the collection according to the specified arguments.updateMany
(ClientSession clientSession, Bson filter, List<? extends Bson> update) Update all documents in the collection according to the specified arguments.updateMany
(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options) Update all documents in the collection according to the specified arguments.updateMany
(ClientSession clientSession, Bson filter, Bson update) Update all documents in the collection according to the specified arguments.updateMany
(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options) Update all documents in the collection according to the specified arguments.updateMany
(Bson filter, List<? extends Bson> update) Update all documents in the collection according to the specified arguments.updateMany
(Bson filter, List<? extends Bson> update, UpdateOptions options) Update all documents in the collection according to the specified arguments.updateMany
(Bson filter, Bson update) Update all documents in the collection according to the specified arguments.updateMany
(Bson filter, Bson update, UpdateOptions options) Update all documents in the collection according to the specified arguments.updateOne
(ClientSession clientSession, Bson filter, List<? extends Bson> update) Update a single document in the collection according to the specified arguments.updateOne
(ClientSession clientSession, Bson filter, List<? extends Bson> update, UpdateOptions options) Update a single document in the collection according to the specified arguments.updateOne
(ClientSession clientSession, Bson filter, Bson update) Update a single document in the collection according to the specified arguments.updateOne
(ClientSession clientSession, Bson filter, Bson update, UpdateOptions options) Update a single document in the collection according to the specified arguments.Update a single document in the collection according to the specified arguments.updateOne
(Bson filter, List<? extends Bson> update, UpdateOptions options) Update a single document in the collection according to the specified arguments.Update a single document in the collection according to the specified arguments.updateOne
(Bson filter, Bson update, UpdateOptions options) Update a single document in the collection according to the specified arguments.updateSearchIndex
(String indexName, Bson definition) Update an Atlas Search index in the collection.watch()
Creates a change stream for this collection.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.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>
Creates a change stream for this collection.Creates a change stream for this collection.<TResult> ChangeStreamPublisher<TResult>
Creates a change stream for this collection.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..withReadConcern
(ReadConcern readConcern) Create a new MongoCollection instance with a different read concern.withReadPreference
(ReadPreference readPreference) Create a new MongoCollection instance with a different read preference.withWriteConcern
(WriteConcern writeConcern) Create a new MongoCollection instance with a different write concern.
-
Method Details
-
getNamespace
MongoNamespace getNamespace()Gets the namespace of this collection.- Returns:
- the namespace
-
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
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
Create a new MongoCollection instance with a different codec registry.The
CodecRegistry
configured by this method is effectively treated by the driver as an instance ofCodecProvider
, whichCodecRegistry
extends. So there is no benefit to defining a class that implementsCodecRegistry
. Rather, an application should always createCodecRegistry
instances using the factory methods inCodecRegistries
.- Parameters:
codecRegistry
- the newCodecRegistry
for the collection- Returns:
- a new MongoCollection instance with the different codec registry
- See Also:
-
withReadPreference
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
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
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
Gets an estimate of the count of documents in a collection using collection metadata.Implementation note: this method is implemented using the MongoDB server's count command
- Returns:
- a publisher with a single element indicating the estimated number of documents
- Since:
- 1.9
- MongoDB documentation
- manual/reference/command/count/#behavior
-
estimatedDocumentCount
Gets an estimate of the count of documents in a collection using collection metadata.Implementation note: this method is implemented using the MongoDB server's count command
- Parameters:
options
- the options describing the count- Returns:
- a publisher with a single element indicating the estimated number of documents
- Since:
- 1.9
- MongoDB documentation
- manual/reference/command/count/#behavior
-
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
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
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
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
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
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
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
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
Finds all documents in the collection.- Parameters:
filter
- the query filter- Returns:
- the fluent find interface
- MongoDB documentation
- Find
-
find
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
Finds all documents in the collection. -
find
Finds all documents in the collection. -
find
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
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
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
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
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
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
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
Deprecated.Superseded by aggregateAggregates 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
@Deprecated <TResult> MapReducePublisher<TResult> mapReduce(String mapFunction, String reduceFunction, Class<TResult> clazz) Deprecated.Superseded by aggregateAggregates 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
@Deprecated MapReducePublisher<TDocument> mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction) Deprecated.Superseded by aggregateAggregates 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
@Deprecated <TResult> MapReducePublisher<TResult> mapReduce(ClientSession clientSession, String mapFunction, String reduceFunction, Class<TResult> clazz) Deprecated.Superseded by aggregateAggregates 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
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
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
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
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
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
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 delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
-
deleteOne
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 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
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 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
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 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
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 delete operation- Returns:
- a publisher with a single element the DeleteResult or with an com.mongodb.MongoException
-
deleteMany
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 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
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 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
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 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
Replace a document in the collection according to the specified arguments.- Parameters:
filter
- the query filter to apply the replace operationreplacement
- the replacement document- Returns:
- a publisher with a single element the UpdateResult
- MongoDB documentation
- Replace
-
replaceOne
Replace a document in the collection according to the specified arguments.- Parameters:
filter
- the query filter to apply 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
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 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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
Atomically find a document and replace it.- Parameters:
filter
- the query filter to apply 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 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 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 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
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
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
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
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
Drops this collection from the Database.- Returns:
- an empty publisher that indicates when the operation has completed
- MongoDB documentation
- Drop Collection
-
drop
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
-
drop
Drops this collection from the Database.- Parameters:
dropCollectionOptions
- various options for dropping the collection- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 4.7
- MongoDB documentation
- Drop Collection
- Since server release
- 6.0
-
drop
Drops this collection from the Database.- Parameters:
clientSession
- the client session with which to associate this operationdropCollectionOptions
- various options for dropping the collection- Returns:
- an empty publisher that indicates when the operation has completed
- Since:
- 4.7
- MongoDB documentation
- Drop Collection
- Since server release
- 6.0
-
createSearchIndex
Create an Atlas Search index for the collection.- Parameters:
indexName
- the name of the search index to create.definition
- Atlas Search index mapping definition.- Returns:
- a
Publisher
with search index name. - Since:
- 4.11
- MongoDB documentation
- Create Search indexes
- Since server release
- 7.0
-
createSearchIndex
Create an Atlas Search index with"default"
name for the collection.- Parameters:
definition
- Atlas Search index mapping definition.- Returns:
- a
Publisher
with search index name. - Since:
- 4.11
- MongoDB documentation
- Create Search indexes
- Since server release
- 7.0
-
createSearchIndexes
Create one or more Atlas Search indexes for the collection.The name can be omitted for a single index, in which case a name will be
"default"
.- Parameters:
searchIndexModels
- the search index models.- Returns:
- a
Publisher
with the search index names in the order specified by the given listSearchIndexModel
s. - Since:
- 4.11
- MongoDB documentation
- Create Search indexes
- Since server release
- 7.0
-
updateSearchIndex
Update an Atlas Search index in the collection.- Parameters:
indexName
- the name of the search index to update.definition
- Atlas Search index mapping definition.- Returns:
- an empty publisher that indicates when the operation has completed.
- Since:
- 4.11
- MongoDB documentation
- Update Search index
- Since server release
- 7.0
-
dropSearchIndex
Drop an Atlas Search index given its name.- Parameters:
indexName
- the name of the search index to drop.- Returns:
- an empty publisher that indicates when the operation has completed.
- Since:
- 4.11
- MongoDB documentation
- Drop Search index
- Since server release
- 7.0
-
listSearchIndexes
ListSearchIndexesPublisher<Document> listSearchIndexes()Get all Atlas Search indexes in this collection.- Returns:
- the fluent list search indexes interface.
- Since:
- 4.11
- Since server release
- 7.0
-
listSearchIndexes
Get all Atlas Search indexes in this collection.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
resultClass
- the class to decode each document into.- Returns:
- the fluent list search indexes interface.
- Since:
- 4.11
- Since server release
- 7.0
-
createIndex
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
-