Store and query data in Firestore in Datastore mode

This page shows you how to store and query data in Firestore in Datastore mode using the Google Cloud console.

Before you begin

Create a database

  1. To create a new database instance, open the Datastore sectionin the Google Cloud console:
    Go to the Datastore page

  2. Select a database mode.

    When you create a new Firestore database, you have the option to useFirestore in either Native Mode or Datastore mode. You can't use bothmodes in the same project.

    Select from one of the database options:

    • Firestore in Native Mode

      Recommended for mobile and web apps. To get started with Firestore, continue in theFirestore Quickstart.

    • Firestore in Datastore Mode

      Recommended for app architectures with backend servers.

    For more guidance on selecting a database mode and for a feature-by-featurecomparison, seechoosing between Native Mode and Datastore Mode.

  3. Select a database location. Datastore mode supports multi-regionand regional locations.

    A multi-region location maximizes availability and durability. Regionallocations offer lower write latency. To learn more about location types,seeDatastore mode locations.The location applies to both Datastore mode databases and App Engine apps foryour Google Cloud project.

    Warning: Once you create your database, you cannot change the location.

    ClickCreate database. After your database finishes initializing, theGoogle Cloud console directs you to the Datastore Entities page.

Store data

  1. Go to the Datastore Entities page in the Google Cloud console.

    Go to the Entities page

    This page lets you store, query, update, and delete data.

  2. ClickCreate entity.

  3. On theCreate an entity page, use[default] forNamespace.

  4. TypeTask in theKind field. LeaveKey identifier set to thedefault value ofNumeric ID (auto-generated).

  5. UnderProperties, use theAdd property button to add these properties:

    NameTypeValueIndexed
    descriptionStringLearn about Datastore.
    createdDate and time(today's date)
    doneBooleanFalse
    Your creation page should now look like this:

    The entity creation window with various properties set

  6. ClickCreate. The console displays theTask entity that you just created.

You just stored data in your database!

Run a query

Datastore mode databases support querying data by kind or byGoogle Query Language (GQL). The instructions below walk you through using bothto query your database.

Run kind queries

  1. ClickQuery by kind.
  2. SelectTask as the kind.

The query results show theTask entity that you created.

Next, add a query clause to restrict the results to entities that meet specificcriteria:

  1. ClickAdd query clause.
  2. In the dropdown lists, selectWHERE,done,==,boolean, andfalse.
  3. ClickRun. The results show theTask entity that youcreated since itsdone value isfalse.A kind query with a filter applied
  4. Now change the query clause toWHERE,done,==,boolean, andtrue. ClickRun. The results do not include theTask entity that youcreated, because itsdone value is nottrue.

Run GQL queries

  1. ClickQuery by GQL.
  2. EnterSELECT * FROM Task as the query. Note thatTask is case sensitive.
  3. ClickRun query.

The query results show theTask entity that you created.

Tip

The GQL query editor supports autocompletion for kinds: When you need to type a kind name, press Ctrl+Space to see a list of the available kinds. Up to 300 alphabetically sorted kinds can appear in the list. For better matches of kinds, type one or more characters.

Add a query filter to restrict the results to entities that meetspecific criteria:

  1. Run a query such asSELECT * FROM Task WHERE done=false. Note thatTaskanddone are case sensitive.The results show theTask entity that you created, since itsdone value isfalse.A GQL query with a filter applied
  2. Now run a query such asSELECT * FROM Task WHERE done=true. The results donot include theTask entity that you created, because itsdone value isnottrue.

Clean up

  1. ClickQuery by kind and ensureTask is the selected kind.
  2. ClickClear to remove any query clauses.
  3. Select theTask entity that you created.
  4. ClickDelete, and then confirm you want to delete theTask entity.Depending on the size of the browser window,Delete might be under theMore actions menu. Oncedeleted, the entity is permanently removed from your database.

That's it, you completed this quickstart!

What's next

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 2025-12-15 UTC.