Group
The Group
class represents a collection group in the database.
You access the groups using the groups.
interface Comment { text: string;}
const db = schema(($) => ({ users: $.collection<User>().sub({ posts: $.collection<UserPost>().sub({ comments: $.collection<Comment>(), }), }), posts: $.collection<Post>().sub({ comments: $.collection<Comment>(), }),}));
groups(db).comments;//=> Group<Comment>
→ Read more about the collection groups
→ Read more about the groups
function
→ Collection group on the Firebase Docs website
type
The entity type.
groups(db).comments;//=> "group"
name
The group name.
groups(db).comments;//=> "comments"
all
The method allows to get all documents in the collection:
await groups(db).comments.all();//=> Doc<Comment>[]
→ Read more about the all
method
query
The method allows to query documents in the collection:
await groups(db).comments.query(($) => $.field("text").eq("Hello"));//=> Doc<Comment>[]
→ Read more about the query
method
count
The method allows counting documents in the collection:
await groups(db).comments.count();//=> 420
→ Read more about the count
method
sum
The method enables summing the collection field values:
await groups(db).comments.sum("age");//=> 42069
→ Read more about the sum
method
average
The method allows to calculate the average of collection field values:
await groups(db).comments.average("age");//=> 42
→ Read more about the sum
method
as
⚠️ Available starting with v10.7.0
The method resolves Typesaurus.SharedGroup
if the model extends the given type. Otherwise, it resolves unknown
preventing the usage of incompatible models:
rename(groups(db).comments.as<TextFields>());
It allows sharing functionality across the db entities in a type-safe way.