Database

Preview:Firestore in Native mode (with Pipeline operations) for Enterpriseedition is subject to the "Pre-GA Offerings Terms" in the GeneralService Terms section of theService SpecificTerms. You can process personaldata for this feature as outlined in theCloud Data Processing Addendum, subjectto the obligations and restrictions described in the agreement under which youaccess Google Cloud. Pre-GA features are available "as is" and might havelimited support. For more information, see thelaunch stagedescriptions.

Description

Returns all the documents within a database across different collections andnested levels.

Syntax

Node.js

constresults=awaitdb.pipeline().database().execute();

Client examples

Web

// Count all documents in the databaseconstresults=awaitexecute(db.pipeline().database().aggregate(countAll().as("total")));
Swift
// Count all documents in the databaseletresults=tryawaitdb.pipeline().database().aggregate([CountAll().as("total")]).execute()

Kotlin

// Count all documents in the databasevalresults=db.pipeline().database().aggregate(AggregateFunction.countAll().alias("total")).execute()

Java

// Count all documents in the databaseTask<Pipeline.Snapshot>results=db.pipeline().database().aggregate(AggregateFunction.countAll().alias("total")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportCount# Count all documents in the databaseresults=client.pipeline().database().aggregate(Count().as_("total")).execute()
Java
// Count all documents in the databasePipeline.Snapshotresults=firestore.pipeline().database().aggregate(countAll().as("total")).execute().get();

Behavior

In order to use thedatabase stage, it must appear as the first stagein the pipeline.

The order of documents returned from thedatabase stage is unstableand shouldn't be relied upon. A subsequent sort stage can be used to obtain adeterministic ordering.

For example, for the following documents:

Node.js

awaitdb.collection('cities').doc('SF').set({name:'San Francsico',state:'California',population:800000});awaitdb.collection('states').doc('CA').set({name:'California',population:39000000});awaitdb.collection('countries').doc('USA').set({name:'United States of America',population:340000000});

Thedatabase stage can be used to retrieve all the documents in the database.

Node.js

constresults=awaitdb.pipeline().database().sort(field('population').ascending()).execute();

This query produces the following documents:

{name:'San Francsico',state:'California',population:800000}{name:'California',population:39000000}{name:'United States of America',population:340000000}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.