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
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
    If you are not the project owner, your account requires the following permissions to complete this quickstart: - Your account requires the
        
        Datastore Owner role
        which contains the datastore.databases.createpermission needed to create a Datastore mode instance.
- Datastore mode requires an active App Engine application.
        If the project doesn't have an application, this quickstart creates one
        for you. In that case, you require the
        appengine.applications.createpermission. The project owner can assign this permission with an IAM custom role.
 
- Your account requires the
        
        Datastore Owner role
        which contains the 
Create a database
- To create a new database instance, open the Datastore section in the Google Cloud console: 
 Go to the Datastore page
- Select a database mode. - When you create a new Firestore database, you have the option to use Firestore in either Native Mode or Datastore mode. You can't use both modes 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 the Firestore 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-feature comparison, see choosing between Native Mode and Datastore Mode. 
- 
  
- Select a database location. Datastore mode supports multi-region and regional locations. - A multi-region location maximizes availability and durability. Regional locations offer lower write latency. To learn more about location types, see Datastore mode locations. The location applies to both Datastore mode databases and App Engine apps for your Google Cloud project. - Click Create database. After your database finishes initializing, the Google Cloud console directs you to the Datastore Entities page. 
Store data
- Go to the Datastore Entities page in the Google Cloud console. - This page lets you store, query, update, and delete data. 
- Click Create entity. 
- On the Create an entity page, use - [default]for Namespace.
- Type - Taskin the Kind field. Leave Key identifier set to the default value of- Numeric ID (auto-generated).
- Under Properties, use the Add property button to add these properties: 
 Your creation page should now look like this:- Name - Type - Value - Indexed - description - String - Learn about Datastore. - created - Date and time - (today's date) - ✓ - done - Boolean - False - ✓   
- Click Create. The console displays the - Taskentity that you just created.
You just stored data in your database!
Run a query
Datastore mode databases support querying data by kind or by Google Query Language (GQL). The instructions below walk you through using both to query your database.
Run kind queries
- Click Query by kind.
- Select Taskas the kind.
The query results show the Task entity that you created.
Next, add a query clause to restrict the results to entities that meet specific criteria:
- Click Add query clause.
- In the dropdown lists, select WHERE,done,==, boolean, and false.
- Click Run. The results show the Taskentity that you created since itsdonevalue isfalse.  
- Now change the query clause to WHERE,done,==, boolean, and true. Click Run. The results do not include theTaskentity that you created, because itsdonevalue is nottrue.
Run GQL queries
- Click Query by GQL.
- Enter SELECT * FROM Taskas the query. Note thatTaskis case sensitive.
- Click Run query.
The query results show the Task entity that you created.
Add a query filter to restrict the results to entities that meet specific criteria:
- Run a query such as SELECT * FROM Task WHERE done=false. Note thatTaskanddoneare case sensitive. The results show theTaskentity that you created, since itsdonevalue isfalse.  
- Now run a query such as SELECT * FROM Task WHERE done=true. The results do not include theTaskentity that you created, because itsdonevalue is nottrue.
Clean up
- Click Query by kind and ensure Taskis the selected kind.
- Click Clear to remove any query clauses.
- Select the Taskentity that you created.
- Click Delete, and then confirm you want to delete the Taskentity. Depending on the size of the browser window, Delete might be under the More actions menu. Once deleted, the entity is permanently removed from your database.
That's it, you completed this quickstart!
What's next
- Learn more about Datastore Queries.
- Learn more about Datastore mode databases.