Docs

Dart: Documents

Read, write and query document collections, count and aggregate, and commit several writes at once with the Dart and Flutter SDK.

Updated Oct 24, 2026

Read, write and query document collections, count and aggregate, and commit several writes at once. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.

#Types and members

SovariaCollections

Document collections (Firestore-style): collections.collection('chats/42/messages').add({...}).

class SovariaCollections

SovariaCollections.SovariaCollections

Create an instance.

SovariaCollections(this._client)

SovariaCollections.collection

CollectionRef collection(String path)

SovariaCollections.collectionGroup

Every collection with this id at any depth (comments, posts/p1/comments, …), like Firestore's collectionGroup: query, count, aggregate and findNearest read them all.

CollectionRef collectionGroup(String collectionId)

Document cursors and __key__ are full document paths in a group.

SovariaCollections.commit

Write several documents atomically ({'op': 'set'|'update'|'delete', 'path': 'c/id', 'data': {...}}).

Future<Map<String, Object?>> commit(List<Map<String, Object?>> writes, {List<Map<String, Object?>> reads = const []})

CollectionRef

class CollectionRef

CollectionRef.path

A property.

final String path

CollectionRef.isGroup

A collection group (see SovariaCollections.collectionGroup).

final bool isGroup

CollectionRef.doc

DocumentRef doc(String id)

CollectionRef.add

Add a document with a new random id; returns its reference.

Future<DocumentRef> add(Map<String, Object?> data)

CollectionRef.query

Field query: query(where: [['age', '>=', 18]], orderBy: [['age', 'desc']], limit: 20).

Future<QueryPage> query({List<Object> where = const [], List<List<Object?>> orderBy = const [], int? limit,
    Map<String, Object?>? startAfter})

A where entry can also be a group: Filter.or([['a', '==', 1], ['b', '<', 2]]).

CollectionRef.findNearest

Vector search (Firestore findNearest): the limit documents whose vectorField (an array of numbers) is closest to queryVector, after the where pre-filter, closest first; each has a distance.

Future<QueryPage> findNearest(String vectorField, List<num> queryVector,
    {required int limit, String distanceMeasure = "", List<Object> where = const [],
    double? distanceThreshold, String? distanceResultField})

distanceMeasure: cosine | euclidean | dot_product. distanceThreshold: at most this distance (cosine/euclidean) or at least this product (dot_product).

CollectionRef.count

Future<int> count({List<Object> where = const []})

CollectionRef.aggregate

count / sum / average on the server: aggregate({'n': Aggregate.count(), 'revenue': Aggregate.sum('total')}, where: [['paid', '==', true]]).

Future<Map<String, num?>> aggregate(Map<String, Map<String, Object?>> aggregations,
    {List<Object> where = const [], List<List<Object?>> orderBy = const [], int? limit})

sum and average use numeric values only; average is null when there are none. With limit they cover the first limit results (in orderBy order); without, every match.

DocumentRef

class DocumentRef

DocumentRef.collection

A property.

final String collection

DocumentRef.id

A property.

final String id

DocumentRef.get

The document's data, or null when it doesn't exist.

Future<Map<String, Object?>?> get()

DocumentRef.set

Future<void> set(Map<String, Object?> data)

DocumentRef.update

Merge fields into the document (others are kept).

Future<void> update(Map<String, Object?> fields)

DocumentRef.delete

Future<void> delete()

QueryPage

class QueryPage

QueryPage.QueryPage

Create an instance.

QueryPage(this.documents, this.hasMore, this.nextCursor)

QueryPage.documents

A property.

final List<Map<String, Object?>> documents

QueryPage.hasMore

A property.

final bool hasMore

QueryPage.nextCursor

A property.

final Map<String, Object?>? nextCursor

QueryPage.QueryPage.fromJson

Create an instance.

factory QueryPage.fromJson(Object? json)

Filter

or / and groups for where (Firestore Filter.or / Filter.and; at most 30 OR terms after expansion).

class Filter

Filter.or

static Map<String, Object> or(List<Object> filters)

Filter.and

static Map<String, Object> and(List<Object> filters)

Aggregate

Aggregations for CollectionRef.aggregate.

class Aggregate

Aggregate.count

static Map<String, Object?> count()

Aggregate.sum

static Map<String, Object?> sum(String field)

Aggregate.average

static Map<String, Object?> average(String field)