Package io.nitric.api.document
Class Collection
- java.lang.Object
-
- io.nitric.api.document.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection
collection(String name)
Create a new sub collection for this top level collection.DocumentRef<Map>
doc(String id)
Create a new collection Document Reference object for given document id andMap
value type.<T> DocumentRef<T>
doc(String id, Class<T> type)
Create a new collection Document Reference object for given document id and value type.String
getName()
Return the collection name.Key
getParent()
Return the collection parent key.Query<Map>
query()
Create a new collection query object with theMap
value type.<T> Query<T>
query(Class<T> type)
Create a new collection query object with the given value type.String
toString()
Return this string representation of this object.
-
-
-
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 andMap
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 theMap
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
-
-