Class CoreRemoteMongoCollectionImpl<DocumentT>
- java.lang.Object
-
- com.mongodb.stitch.core.services.mongodb.remote.internal.CoreRemoteMongoCollectionImpl<DocumentT>
-
- All Implemented Interfaces:
CoreRemoteMongoCollection<DocumentT>
public class CoreRemoteMongoCollectionImpl<DocumentT> extends Object implements CoreRemoteMongoCollection<DocumentT>
-
-
Method Summary
Modifier and Type Method Description CoreRemoteAggregateIterable<DocumentT>
aggregate(List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.<ResultT> CoreRemoteAggregateIterable<ResultT>
aggregate(List<? extends Bson> pipeline, Class<ResultT> resultClass)
Aggregates documents according to the specified aggregation pipeline.long
count()
Counts the number of documents in the collection.long
count(Bson filter)
Counts the number of documents in the collection according to the given options.long
count(Bson filter, RemoteCountOptions options)
Counts the number of documents in the collection according to the given options.RemoteDeleteResult
deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter.RemoteDeleteResult
deleteOne(Bson filter)
Removes at most one document from the collection that matches the given filter.<ResultT> ResultT
executeFindOne(Bson filter, RemoteFindOptions options, Class<ResultT> resultClass)
CoreRemoteFindIterable<DocumentT>
find()
Finds all documents in the collection.<ResultT> CoreRemoteFindIterable<ResultT>
find(Class<ResultT> resultClass)
Finds all documents in the collection.CoreRemoteFindIterable<DocumentT>
find(Bson filter)
Finds all documents in the collection.<ResultT> CoreRemoteFindIterable<ResultT>
find(Bson filter, Class<ResultT> resultClass)
Finds all documents in the collection.DocumentT
findOne()
Finds a document in the collection<ResultT> ResultT
findOne(Class<ResultT> resultClass)
Finds a document in the collection.DocumentT
findOne(Bson filter)
Finds a document in the collection.DocumentT
findOne(Bson filter, RemoteFindOptions options)
Finds a document in the collection.<ResultT> ResultT
findOne(Bson filter, RemoteFindOptions options, Class<ResultT> resultClass)
Finds a document in the collection.<ResultT> ResultT
findOne(Bson filter, Class<ResultT> resultClass)
Finds a document in the collection.DocumentT
findOneAndDelete(Bson filter)
Finds a document in the collection and delete it.DocumentT
findOneAndDelete(Bson filter, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and delete it.<ResultT> ResultT
findOneAndDelete(Bson filter, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and delete it.<ResultT> ResultT
findOneAndDelete(Bson filter, Class<ResultT> resultClass)
Finds a document in the collection and delete it.DocumentT
findOneAndReplace(Bson filter, Bson replacement)
Finds a document in the collection and replaces it with the given documentDocumentT
findOneAndReplace(Bson filter, Bson replacement, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and replaces it with the given document<ResultT> ResultT
findOneAndReplace(Bson filter, Bson replacement, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given document<ResultT> ResultT
findOneAndReplace(Bson filter, Bson replacement, Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given documentDocumentT
findOneAndUpdate(Bson filter, Bson update)
Finds a document in the collection and performs the given update.DocumentT
findOneAndUpdate(Bson filter, Bson update, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and performs the given update.<ResultT> ResultT
findOneAndUpdate(Bson filter, Bson update, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.<ResultT> ResultT
findOneAndUpdate(Bson filter, Bson update, Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.CodecRegistry
getCodecRegistry()
Get the codec registry for the CoreRemoteMongoCollection.Class<DocumentT>
getDocumentClass()
Get the class of documents stored in this collection.MongoNamespace
getNamespace()
Gets the namespace of this collection.RemoteInsertManyResult
insertMany(List<? extends DocumentT> documents)
Inserts one or more documents.RemoteInsertOneResult
insertOne(DocumentT document)
Inserts the provided document.CoreSync<DocumentT>
sync()
A set of synchronization related operations at the collection level.RemoteUpdateResult
updateMany(Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.RemoteUpdateResult
updateMany(Bson filter, Bson update, RemoteUpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.RemoteUpdateResult
updateOne(Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.RemoteUpdateResult
updateOne(Bson filter, Bson update, RemoteUpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.Stream<ChangeEvent<DocumentT>>
watch()
Watches a collection.Stream<ChangeEvent<DocumentT>>
watch(BsonValue... ids)
Watches specified IDs in a collection.Stream<ChangeEvent<DocumentT>>
watch(ObjectId... ids)
Watches specified IDs in a collection.Stream<CompactChangeEvent<DocumentT>>
watchCompact(BsonValue... ids)
Watches specified IDs in a collection.Stream<CompactChangeEvent<DocumentT>>
watchCompact(ObjectId... ids)
Watches specified IDs in a collection.Stream<ChangeEvent<DocumentT>>
watchWithFilter(BsonDocument matchFilter)
Watches a collection.CoreRemoteMongoCollection<DocumentT>
withCodecRegistry(CodecRegistry codecRegistry)
Create a new CoreRemoteMongoCollection instance with a different codec registry.<NewDocumentT>
CoreRemoteMongoCollection<NewDocumentT>withDocumentClass(Class<NewDocumentT> clazz)
Create a new CoreRemoteMongoCollection instance with a different default class to cast any documents returned from the database into.
-
-
-
Method Detail
-
getNamespace
public MongoNamespace getNamespace()
Gets the namespace of this collection.- Specified by:
getNamespace
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the namespace
-
getDocumentClass
public Class<DocumentT> getDocumentClass()
Get the class of documents stored in this collection.- Specified by:
getDocumentClass
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the class
-
getCodecRegistry
public CodecRegistry getCodecRegistry()
Get the codec registry for the CoreRemoteMongoCollection.- Specified by:
getCodecRegistry
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the
CodecRegistry
-
withDocumentClass
public <NewDocumentT> CoreRemoteMongoCollection<NewDocumentT> withDocumentClass(Class<NewDocumentT> clazz)
Description copied from interface:CoreRemoteMongoCollection
Create a new CoreRemoteMongoCollection instance with a different default class to cast any documents returned from the database into.- Specified by:
withDocumentClass
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
NewDocumentT
- 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 CoreRemoteMongoCollection instance with the different default class
-
withCodecRegistry
public CoreRemoteMongoCollection<DocumentT> withCodecRegistry(CodecRegistry codecRegistry)
Description copied from interface:CoreRemoteMongoCollection
Create a new CoreRemoteMongoCollection instance with a different codec registry.- Specified by:
withCodecRegistry
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
codecRegistry
- the newCodecRegistry
for the collection.- Returns:
- a new CoreRemoteMongoCollection instance with the different codec registry
-
count
public long count()
Counts the number of documents in the collection.- Specified by:
count
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the number of documents in the collection
-
count
public long count(Bson filter)
Counts the number of documents in the collection according to the given options.- Specified by:
count
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter- Returns:
- the number of documents in the collection
-
count
public long count(Bson filter, RemoteCountOptions options)
Counts the number of documents in the collection according to the given options.- Specified by:
count
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filteroptions
- the options describing the count- Returns:
- the number of documents in the collection
-
findOne
public DocumentT findOne()
Finds a document in the collection- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the resulting document
-
findOne
public <ResultT> ResultT findOne(Class<ResultT> resultClass)
Finds a document in the collection.- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type- Parameters:
resultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOne
public DocumentT findOne(Bson filter)
Finds a document in the collection.- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter- Returns:
- the resulting document
-
findOne
public <ResultT> ResultT findOne(Bson filter, Class<ResultT> resultClass)
Finds a document in the collection.- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOne
public DocumentT findOne(Bson filter, RemoteFindOptions options)
Finds a document in the collection.- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filteroptions
- A RemoteFindOptions struct- Returns:
- the resulting document
-
findOne
public <ResultT> ResultT findOne(Bson filter, RemoteFindOptions options, Class<ResultT> resultClass)
Finds a document in the collection.- Specified by:
findOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filteroptions
- A RemoteFindOptions structresultClass
- the class to decode each document into- Returns:
- the resulting document
-
executeFindOne
public <ResultT> ResultT executeFindOne(Bson filter, RemoteFindOptions options, Class<ResultT> resultClass)
-
find
public CoreRemoteFindIterable<DocumentT> find()
Finds all documents in the collection.- Specified by:
find
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the find iterable interface
-
find
public <ResultT> CoreRemoteFindIterable<ResultT> find(Class<ResultT> resultClass)
Finds all documents in the collection.- Specified by:
find
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
resultClass
- the class to decode each document into- Returns:
- the find iterable interface
-
find
public CoreRemoteFindIterable<DocumentT> find(Bson filter)
Finds all documents in the collection.- Specified by:
find
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter- Returns:
- the find iterable interface
-
find
public <ResultT> CoreRemoteFindIterable<ResultT> find(Bson filter, Class<ResultT> resultClass)
Finds all documents in the collection.- Specified by:
find
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterresultClass
- the class to decode each document into- Returns:
- the find iterable interface
-
aggregate
public CoreRemoteAggregateIterable<DocumentT> aggregate(List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.- Specified by:
aggregate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
pipeline
- the aggregation pipeline- Returns:
- an iterable containing the result of the aggregation operation
-
aggregate
public <ResultT> CoreRemoteAggregateIterable<ResultT> aggregate(List<? extends Bson> pipeline, Class<ResultT> resultClass)
Aggregates documents according to the specified aggregation pipeline.- Specified by:
aggregate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
pipeline
- the aggregation pipelineresultClass
- the class to decode each document into- Returns:
- an iterable containing the result of the aggregation operation
-
insertOne
public RemoteInsertOneResult insertOne(DocumentT document)
Inserts the provided document. If the document is missing an identifier, the client should generate one.- Specified by:
insertOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
document
- the document to insert- Returns:
- the result of the insert one operation
-
insertMany
public RemoteInsertManyResult insertMany(List<? extends DocumentT> documents)
Inserts one or more documents.- Specified by:
insertMany
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
documents
- the documents to insert- Returns:
- the result of the insert many operation
-
deleteOne
public RemoteDeleteResult 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.- Specified by:
deleteOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- the result of the remove one operation
-
deleteMany
public RemoteDeleteResult deleteMany(Bson filter)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Specified by:
deleteMany
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- the result of the remove many operation
-
updateOne
public RemoteUpdateResult updateOne(Bson filter, Bson update)
Update a single document in the collection according to the specified arguments.- Specified by:
updateOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- 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:
- the result of the update one operation
-
updateOne
public RemoteUpdateResult updateOne(Bson filter, Bson update, RemoteUpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.- Specified by:
updateOne
in interfaceCoreRemoteMongoCollection<DocumentT>
- 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.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update one operation
-
updateMany
public RemoteUpdateResult updateMany(Bson filter, Bson update)
Update all documents in the collection according to the specified arguments.- Specified by:
updateMany
in interfaceCoreRemoteMongoCollection<DocumentT>
- 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:
- the result of the update many operation
-
updateMany
public RemoteUpdateResult updateMany(Bson filter, Bson update, RemoteUpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.- Specified by:
updateMany
in interfaceCoreRemoteMongoCollection<DocumentT>
- 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.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update many operation
-
findOneAndUpdate
public DocumentT findOneAndUpdate(Bson filter, Bson update)
Finds a document in the collection and performs the given update.- Specified by:
findOneAndUpdate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filterupdate
- the update document- Returns:
- the resulting document
-
findOneAndUpdate
public <ResultT> ResultT findOneAndUpdate(Bson filter, Bson update, Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.- Specified by:
findOneAndUpdate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterupdate
- the update documentresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOneAndUpdate
public DocumentT findOneAndUpdate(Bson filter, Bson update, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and performs the given update.- Specified by:
findOneAndUpdate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filterupdate
- the update documentoptions
- A RemoteFindOneAndModifyOptions struct- Returns:
- the resulting document
-
findOneAndUpdate
public <ResultT> ResultT findOneAndUpdate(Bson filter, Bson update, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and performs the given update.- Specified by:
findOneAndUpdate
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterupdate
- the update documentoptions
- A RemoteFindOneAndModifyOptions structresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOneAndReplace
public DocumentT findOneAndReplace(Bson filter, Bson replacement)
Finds a document in the collection and replaces it with the given document- Specified by:
findOneAndReplace
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filterreplacement
- the document to replace the matched document with- Returns:
- the resulting document
-
findOneAndReplace
public <ResultT> ResultT findOneAndReplace(Bson filter, Bson replacement, Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given document- Specified by:
findOneAndReplace
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterreplacement
- the document to replace the matched document withresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOneAndReplace
public DocumentT findOneAndReplace(Bson filter, Bson replacement, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and replaces it with the given document- Specified by:
findOneAndReplace
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filterreplacement
- the document to replace the matched document withoptions
- A RemoteFindOneAndModifyOptions struct- Returns:
- the resulting document
-
findOneAndReplace
public <ResultT> ResultT findOneAndReplace(Bson filter, Bson replacement, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and replaces it with the given document- Specified by:
findOneAndReplace
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterreplacement
- the document to replace the matched document withoptions
- A RemoteFindOneAndModifyOptions structresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOneAndDelete
public DocumentT findOneAndDelete(Bson filter)
Finds a document in the collection and delete it.- Specified by:
findOneAndDelete
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filter- Returns:
- the resulting document
-
findOneAndDelete
public <ResultT> ResultT findOneAndDelete(Bson filter, Class<ResultT> resultClass)
Finds a document in the collection and delete it.- Specified by:
findOneAndDelete
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterresultClass
- the class to decode each document into- Returns:
- the resulting document
-
findOneAndDelete
public DocumentT findOneAndDelete(Bson filter, RemoteFindOneAndModifyOptions options)
Finds a document in the collection and delete it.- Specified by:
findOneAndDelete
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
filter
- the query filteroptions
- A RemoteFindOneAndModifyOptions struct- Returns:
- the resulting document
-
findOneAndDelete
public <ResultT> ResultT findOneAndDelete(Bson filter, RemoteFindOneAndModifyOptions options, Class<ResultT> resultClass)
Finds a document in the collection and delete it.- Specified by:
findOneAndDelete
in interfaceCoreRemoteMongoCollection<DocumentT>
- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filteroptions
- A RemoteFindOneAndModifyOptions structresultClass
- the class to decode each document into- Returns:
- the resulting document
-
watch
public Stream<ChangeEvent<DocumentT>> watch() throws InterruptedException, IOException
Watches a collection. The resulting stream will be notified of all events on this collection that the active user is authorized to see based on the configured MongoDB rules.- Specified by:
watch
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
watch
public Stream<ChangeEvent<DocumentT>> watch(ObjectId... ids) throws InterruptedException, IOException
Watches specified IDs in a collection. This convenience overload supports the use case of non-BsonValue
instances ofObjectId
by wrapping them inBsonObjectId
instances for the user.- Specified by:
watch
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
ids
- unique object identifiers of the IDs to watch.- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
watch
public Stream<ChangeEvent<DocumentT>> watch(BsonValue... ids) throws InterruptedException, IOException
Watches specified IDs in a collection.- Specified by:
watch
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
ids
- the ids to watch.- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
watchWithFilter
public Stream<ChangeEvent<DocumentT>> watchWithFilter(BsonDocument matchFilter) throws InterruptedException, IOException
Watches a collection. The provided BSON document will be used as a match expression filter on the change events coming from the stream. See https://docs.mongodb.com/manual/reference/operator/aggregation/match/ for documentation around how to define a match filter. Defining the match expression to filter ChangeEvents is similar to defining the match expression for triggers: https://docs.mongodb.com/stitch/triggers/database-triggers/- Specified by:
watchWithFilter
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
matchFilter
- the $match filter to apply to incoming change events- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
watchCompact
public Stream<CompactChangeEvent<DocumentT>> watchCompact(ObjectId... ids) throws InterruptedException, IOException
Watches specified IDs in a collection. Requests a stream where the full document of update events, and several other unnecessary fields are omitted from the change event objects returned by the server. This can save on network usage when watching large documents This convenience overload supports the use case of non-BsonValue
instances ofObjectId
by wrapping them inBsonObjectId
instances for the user.- Specified by:
watchCompact
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
ids
- unique object identifiers of the IDs to watch.- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
watchCompact
public Stream<CompactChangeEvent<DocumentT>> watchCompact(BsonValue... ids) throws InterruptedException, IOException
Watches specified IDs in a collection. Requests a stream where the full document of update events, and several other unnecessary fields are omitted from the change event objects returned by the server. This can save on network usage when watching large documents- Specified by:
watchCompact
in interfaceCoreRemoteMongoCollection<DocumentT>
- Parameters:
ids
- the ids to watch.- Returns:
- the stream of change events.
- Throws:
InterruptedException
IOException
-
sync
@Nullable public CoreSync<DocumentT> sync()
Description copied from interface:CoreRemoteMongoCollection
A set of synchronization related operations at the collection level.- Specified by:
sync
in interfaceCoreRemoteMongoCollection<DocumentT>
- Returns:
- set of sync operations for this collection
-
-