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

        Task<Long> count()
        Counts the number of documents in the collection.
        Returns:
        a task containing the number of documents in the collection
      • count

        Task<Long> count​(Bson filter)
        Counts the number of documents in the collection according to the given options.
        Parameters:
        filter - the query filter
        Returns:
        a task containing the number of documents in the collection
      • count

        Task<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:
        a task containing the number of documents in the collection
      • 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

        Task<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:
        a task containing the result of the insert one operation
      • insertMany

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

        Task<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:
        a task containing the result of the remove one operation
      • deleteMany

        Task<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:
        a task containing the result of the remove many operation
      • updateOne

        Task<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:
        a task containing the result of the update one operation
      • updateOne

        Task<RemoteUpdateResult> updateOne​(Bson filter,
                                           Bson update,
                                           RemoteUpdateOptions updateOptions)
        Update a single document in the collection according to the specified arguments.
        Example:
        // Update one document and handle the result.
        // 
        Document filterDoc = new Document("name", "board game");
        Document updateDoc = new Document("$inc", new Document("quantity", 5));
        RemoteUpdateOptions options = new RemoteUpdateOptions().upsert(true);
        
        final Task <RemoteUpdateResult> updateTask =
          itemsCollection.updateOne(filterDoc, updateDoc, options);
        
        updateTask.addOnCompleteListener(new OnCompleteListener <RemoteUpdateResult> () {
            @Override
            public void onComplete(@NonNull Task <RemoteUpdateResult> task) {
                if (task.isSuccessful()) {
                    if (task.getResult().getUpsertedId() != null) {
                        String upsertedId = task.getResult().getUpsertedId().toString();
                        Log.d("app", String.format("successfully upserted document with id: %s",
                          upsertedId));
                    } else {
                        long numMatched = task.getResult().getMatchedCount();
                        long numModified = task.getResult().getModifiedCount();
                        Log.d("app", String.format("successfully matched %d and modified %d documents",
                              numMatched, numModified));
                    }
                } else {
                    Log.e("app", "failed to update document with: ", task.getException());
                }
            }
        });
        
        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:
        a task containing the result of the update one operation
      • updateMany

        Task<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:
        a task containing the result of the update many operation
      • updateMany

        Task<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:
        a task containing the result of the update many operation
      • sync

        Sync<DocumentT> sync()
        A set of synchronization related operations on this collection.

        WARNING: This is a BETA feature and the API and on-device storage format are subject to change.

        Returns:
        set of sync operations for this collection