Class Collection


  • public class Collection
    extends Object

    Provides a Collection class.

    The example below illustrates the Document Collection API.

    
     import io.nitric.api.document.Documents;
     import java.util.Map;
     ...
    
     // Create a customers collection
     var customers = Documents.collection("customers");
    
     // Store a new customer document
     var customerMap = Map.of("email", "[email protected]", "status", "active");
    
     customers.doc("[email protected]").set(customerMap);
    
     // Get customer document ref and content
     var customerRef = customers.doc("[email protected]");
    
     customerMap = customerRef.get();
    
     // Delete a customer document
     customers.doc("[email protected]").delete();
     
    • Method Detail

      • getName

        public String getName()
        Return the collection name.
        Returns:
        the collection name
      • getParent

        public Key getParent()
        Return the collection parent key.
        Returns:
        the collection parent key
      • doc

        public DocumentRef<Map> doc​(String id)
        Create a new collection Document Reference object for given document id and Map value type.
        Parameters:
        id - the document unique id (required)
        Returns:
        new collection document reference
      • doc

        public <T> DocumentRef<T> doc​(String id,
                                      Class<T> type)
        Create a new collection Document Reference object for given document id and value type.
        Parameters:
        id - the document unique id (required)
        type - the document value type (required)
        Returns:
        new collection document reference
      • query

        public Query<Map> query()
        Create a new collection query object with the Map value type.
        Returns:
        a new collection query object
      • query

        public <T> Query<T> query​(Class<T> type)
        Create a new collection query object with the given value type.
        Parameters:
        type - the query value type (required)
        Returns:
        a new collection query object
      • collection

        public Collection collection​(String name)
        Create a new sub collection for this top level collection.
        Parameters:
        name - the name of the sub collection (required)
        Returns:
        a new sub collection for the parent collection
      • toString

        public String toString()
        Return this string representation of this object.
        Overrides:
        toString in class Object
        Returns:
        the string representation of this object