Add and query data with Core operations

The Core operations for adding and querying data described on this page are the same as those available in Firestore Standard. If you are familiar with Firestore Standard edition, you can add and query data in Firestore Enterprise the same way.

We're excited for you to try out Pipeline operations, but for this Preview you should be aware of Core operations:

  • You will use Core add operations to populate data during the Preview.
  • You can use Core operations for realtime and offline support just like in Standard edition. Pipeline queries don't have realtime and offline capabilities yet.

Add data to Firestore with Core operations

Core operations support adding and querying data. Pipeline operations are only for querying data. So for Preview activities, you will use Core operations to populate your new Pipelines-capable database.

As a refresher on Core, the two primary methods for writing data are set() and add(). Understanding the difference is key to managing your documents effectively.

You can think of these operations in the following way:

  • set(): Use this when you want to specify a document's ID yourself. If a document with that ID already exists, set() will overwrite it completely unless you use the merge option. If it doesn't exist, set() will create it.
  • add(): Use this when you want Firestore to automatically generate a unique ID for your new document. This is useful when you are adding documents to a collection and don't have a natural identifier to use.

For a comprehensive guide on adding and updating documents, including how to handle nested objects, arrays, and server timestamps, refer to the official documentation on Adding data to Cloud Firestore.

Read data from Firestore with Core operations

Retrieving data from Firestore with Core operations functions exactly like in Firestore Standard edition, including support for realtime updates and offline capabilities.

There are a few ways to retrieve your data:

  • Get a document once: The simplest way to read data is to fetch a document or a query result a single time.
  • Listen for realtime updates: You can set a listener on a document or query to receive updates in realtime as the data changes.
  • Source options: For applications with offline capabilities, you can specify whether to retrieve data from the server, the local cache, or let the SDK decide.

To learn more about performing simple and compound queries, ordering and limiting data, and working with custom objects, see the detailed documentation on Getting data with Cloud Firestore.