Class Collection


  • public class Collection
    extends AbstractCollection

    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

      • 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
      • collection

        public CollectionGroup collection​(String name)
        Create a new sub collection query group for this collection.
        Parameters:
        name - the name of the sub collection (required)
        Returns:
        a new sub collection query group for the parent collection