Interface RemoteMongoCollection<DocumentT>

  • Type Parameters:
    DocumentT - The type that this collection will encode documents from and decode documents to.
    All Known Implementing Classes:
    RemoteMongoCollectionImpl

    public interface RemoteMongoCollection<DocumentT>
    The RemoteMongoCollection interface.
    • Method Detail

      • getNamespace

        MongoNamespace getNamespace()
        Gets the namespace of this collection.
        Returns:
        the namespace
      • getDocumentClass

        Class<DocumentT> getDocumentClass()
        Get the class of documents stored in this collection.
        Returns:
        the class
      • getCodecRegistry

        CodecRegistry getCodecRegistry()
        Get the codec registry for the RemoteMongoCollection.
        Returns:
        the CodecRegistry
      • withDocumentClass

        <NewDocumentT> RemoteMongoCollection<NewDocumentT> withDocumentClass​(Class<NewDocumentT> clazz)
        Create a new RemoteMongoCollection instance with a different default class to cast any documents returned from the database into.
        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 RemoteMongoCollection instance with the different default class
      • withCodecRegistry

        RemoteMongoCollection<DocumentT> withCodecRegistry​(CodecRegistry codecRegistry)
        Create a new RemoteMongoCollection instance with a different codec registry.
        Parameters:
        codecRegistry - the new CodecRegistry for the collection.
        Returns:
        a new RemoteMongoCollection instance with the different codec registry
      • count

        long count()
        Counts the number of documents in the collection.
        Returns:
        the number of documents in the collection
      • count

        long count​(Bson filter)
        Counts the number of documents in the collection according to the given options.
        Parameters:
        filter - the query filter
        Returns:
        the number of documents in the collection
      • count

        long count​(Bson filter,
                   RemoteCountOptions options)
        Counts the number of documents in the collection according to the given options.
        Parameters:
        filter - the query filter
        options - the options describing the count
        Returns:
        the number of documents in the collection
      • findOne

        DocumentT findOne()
        Finds a document in the collection.
        Returns:
        a task containing the result of the find one operation
      • findOne

        <ResultT> ResultT findOne​(Class<ResultT> resultClass)
        Finds a document in the collection.
        Type Parameters:
        ResultT - the target document type
        Parameters:
        resultClass - the class to decode each document into
        Returns:
        a task containing the result of the find one operation
      • findOne

        DocumentT findOne​(Bson filter)
        Finds a document in the collection.
        Parameters:
        filter - the query filter
        Returns:
        a task containing the result of the find one operation
      • findOne

        <ResultT> ResultT findOne​(Bson filter,
                                  Class<ResultT> resultClass)
        Finds a document in the collection.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        resultClass - the class to decode each document into
        Returns:
        a task containing the result of the find one operation
      • findOne

        DocumentT findOne​(Bson filter,
                          RemoteFindOptions options)
        Finds a document in the collection.
        Parameters:
        filter - the query filter
        options - A RemoteFindOptions struct
        Returns:
        a task containing the result of the find one operation
      • findOne

        <ResultT> ResultT findOne​(Bson filter,
                                  RemoteFindOptions options,
                                  Class<ResultT> resultClass)
        Finds a document in the collection.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        options - A RemoteFindOptions struct
        resultClass - the class to decode each document into
        Returns:
        a task containing the result of the find one operation
      • find

        <ResultT> RemoteFindIterable<ResultT> find​(Class<ResultT> resultClass)
        Finds all documents in the collection.
        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

        RemoteFindIterable<DocumentT> find​(Bson filter)
        Finds all documents in the collection.
        Parameters:
        filter - the query filter
        Returns:
        the find iterable interface
      • find

        <ResultT> RemoteFindIterable<ResultT> find​(Bson filter,
                                                   Class<ResultT> resultClass)
        Finds all documents in the collection.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        resultClass - the class to decode each document into
        Returns:
        the find iterable interface
      • aggregate

        RemoteAggregateIterable<DocumentT> aggregate​(List<? extends Bson> pipeline)
        Aggregates documents according to the specified aggregation pipeline.
        Parameters:
        pipeline - the aggregation pipeline
        Returns:
        an iterable containing the result of the aggregation operation
      • aggregate

        <ResultT> RemoteAggregateIterable<ResultT> aggregate​(List<? extends Bson> pipeline,
                                                             Class<ResultT> resultClass)
        Aggregates documents according to the specified aggregation pipeline.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        pipeline - the aggregation pipeline
        resultClass - the class to decode each document into
        Returns:
        an iterable containing the result of the aggregation operation
      • insertOne

        RemoteInsertOneResult insertOne​(DocumentT document)
        Inserts the provided document. If the document is missing an identifier, the client should generate one.
        Parameters:
        document - the document to insert
        Returns:
        the result of the insert one operation
      • insertMany

        RemoteInsertManyResult insertMany​(List<? extends DocumentT> documents)
        Inserts one or more documents.
        Parameters:
        documents - the documents to insert
        Returns:
        the result of the insert many operation
      • deleteOne

        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.
        Parameters:
        filter - the query filter to apply the the delete operation
        Returns:
        the result of the remove one operation
      • deleteMany

        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.
        Parameters:
        filter - the query filter to apply the the delete operation
        Returns:
        the result of the remove many operation
      • updateOne

        RemoteUpdateResult updateOne​(Bson filter,
                                     Bson update)
        Update a single document in the collection according to the specified arguments.
        Parameters:
        filter - a document describing the query filter, which may not be null.
        update - a document describing the update, which may not be null. The update to apply must include only update operators.
        Returns:
        the result of the update one operation
      • updateOne

        RemoteUpdateResult updateOne​(Bson filter,
                                     Bson update,
                                     RemoteUpdateOptions updateOptions)
        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.
        updateOptions - the options to apply to the update operation
        Returns:
        the result of the update one operation
      • findOneAndUpdate

        DocumentT findOneAndUpdate​(Bson filter,
                                   Bson update)
        Finds a document in the collection and performs the given update.
        Parameters:
        filter - the query filter
        update - the update document
        Returns:
        the resulting document
      • findOneAndUpdate

        <ResultT> ResultT findOneAndUpdate​(Bson filter,
                                           Bson update,
                                           Class<ResultT> resultClass)
        Finds a document in the collection and performs the given update.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        update - the update document
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • findOneAndUpdate

        DocumentT findOneAndUpdate​(Bson filter,
                                   Bson update,
                                   RemoteFindOneAndModifyOptions options)
        Finds a document in the collection and performs the given update.
        Parameters:
        filter - the query filter
        update - the update document
        options - A RemoteFindOneAndModifyOptions struct
        Returns:
        the resulting document
      • findOneAndUpdate

        <ResultT> ResultT findOneAndUpdate​(Bson filter,
                                           Bson update,
                                           RemoteFindOneAndModifyOptions options,
                                           Class<ResultT> resultClass)
        Finds a document in the collection and performs the given update.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        update - the update document
        options - A RemoteFindOneAndModifyOptions struct
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • findOneAndReplace

        DocumentT findOneAndReplace​(Bson filter,
                                    Bson replacement)
        Finds a document in the collection and replaces it with the given document.
        Parameters:
        filter - the query filter
        replacement - the document to replace the matched document with
        Returns:
        the resulting document
      • findOneAndReplace

        <ResultT> ResultT findOneAndReplace​(Bson filter,
                                            Bson replacement,
                                            Class<ResultT> resultClass)
        Finds a document in the collection and replaces it with the given document.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        replacement - the document to replace the matched document with
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • findOneAndReplace

        DocumentT findOneAndReplace​(Bson filter,
                                    Bson replacement,
                                    RemoteFindOneAndModifyOptions options)
        Finds a document in the collection and replaces it with the given document.
        Parameters:
        filter - the query filter
        replacement - the document to replace the matched document with
        options - A RemoteFindOneAndModifyOptions struct
        Returns:
        the resulting document
      • findOneAndReplace

        <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.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        replacement - the document to replace the matched document with
        options - A RemoteFindOneAndModifyOptions struct
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • findOneAndDelete

        DocumentT findOneAndDelete​(Bson filter)
        Finds a document in the collection and delete it.
        Parameters:
        filter - the query filter
        Returns:
        the resulting document
      • findOneAndDelete

        <ResultT> ResultT findOneAndDelete​(Bson filter,
                                           Class<ResultT> resultClass)
        Finds a document in the collection and delete it.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • findOneAndDelete

        DocumentT findOneAndDelete​(Bson filter,
                                   RemoteFindOneAndModifyOptions options)
        Finds a document in the collection and delete it.
        Parameters:
        filter - the query filter
        options - A RemoteFindOneAndModifyOptions struct
        Returns:
        the resulting document
      • findOneAndDelete

        <ResultT> ResultT findOneAndDelete​(Bson filter,
                                           RemoteFindOneAndModifyOptions options,
                                           Class<ResultT> resultClass)
        Finds a document in the collection and delete it.
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        options - A RemoteFindOneAndModifyOptions struct
        resultClass - the class to decode each document into
        Returns:
        the resulting document
      • updateMany

        RemoteUpdateResult updateMany​(Bson filter,
                                      Bson update)
        Update all documents in the collection according to the specified arguments.
        Parameters:
        filter - a document describing the query filter, which may not be null.
        update - a document describing the update, which may not be null. The update to apply must include only update operators.
        Returns:
        the result of the update many operation
      • updateMany

        RemoteUpdateResult updateMany​(Bson filter,
                                      Bson update,
                                      RemoteUpdateOptions updateOptions)
        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.
        updateOptions - the options to apply to the update operation
        Returns:
        the result of the update many operation
      • watchWithFilter

        ChangeStream<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/
        Parameters:
        matchFilter - the $match filter to apply to incoming change events
        Returns:
        the stream of change events.
        Throws:
        InterruptedException - if the operation is interrupted.
        IOException - if the operation fails.
      • watchWithFilter

        ChangeStream<ChangeEvent<DocumentT>> watchWithFilter​(Document 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/
        Parameters:
        matchFilter - the $match filter to apply to incoming change events
        Returns:
        the stream of change events.
        Throws:
        InterruptedException - if the operation is interrupted.
        IOException - if the operation fails.
      • watchCompact

        ChangeStream<CompactChangeEvent<DocumentT>> watchCompact​(ObjectId... ids)
                                                          throws InterruptedException,
                                                                 IOException
        Watches specified IDs in a collection. This convenience overload supports the use case of non-BsonValue instances of ObjectId. 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.
        Parameters:
        ids - unique object identifiers of the IDs to watch.
        Returns:
        the stream of change events.
        Throws:
        InterruptedException - if the operation is interrupted.
        IOException - if the operation fails.
      • watchCompact

        ChangeStream<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.
        Parameters:
        ids - the ids to watch.
        Returns:
        the stream of change events.
        Throws:
        InterruptedException - if the operation is interrupted.
        IOException - if the operation fails.