Cloud Firestore Enterprise edition with MongoDB compatibility is now available!
Learn more.
Quickstart: Create a database and connect to it
Stay organized with collections
Save and categorize content based on your preferences.
Relevant to Cloud Firestore Enterprise edition only.
|
Learn how to create a Cloud Firestore with MongoDB compatibility database and connect to it with the
mongosh
tool.
Before you begin
-
If you haven't already, create a Firebase project: In the
Firebase console, click Add project,
then follow the on-screen instructions to create a Firebase project or to
add Firebase services to an existing Google Cloud project.
- Install the
mongosh
tool
Create a Cloud Firestore with MongoDB compatibility database and retrieve the connection string
In the
Firebase console, create a new Firestore Enterprise edition database.
Cloud Firestore with MongoDB compatibility requires Firestore Enterprise edition:
-
In the Firebase console, go to the Firestore Database page.
Go to Firestore Database
- Click the database that you want to authenticate.
- In the Explorer panel, click more_vert View more.
- Select Connect using MongoDB tools.
- Copy the connection string.
The connection string depends on the UID of the database (system-generated)
and the location of database:
UID.LOCATION.firestore.goog
Create a user for SCRAM authentication
In the Google Cloud console, create a new database user and assign
the user Identity and Access Management permissions.
-
In the Google Cloud console, go to the Databases page.
Go to Databases
- Select the database from the list of databases.
- In the navigation menu, click Auth.
- Click Add User.
- Enter a username.
- Select an Identity and Access Management role for the user.
- Click create. The database creates a user and shows you the user's
generated password. Copy and save this password. You will not be able to retrieve
this password later..
Connect using mongosh
Use the connection string, username, and password to connect to your
database, run mongosh
locally with the following configuration options.
mongosh 'mongodb://USERNAME:PASSWORD@CONNECTION_STRING:443/DATABASE_ID?loadBalanced=true&authMechanism=SCRAM-SHA-256&tls=true&retryWrites=false'
Replace the following:
- USERNAME: the name of the database user you created.
- PASSWORD: the generated password for the database user you created.
- CONNECTION_STRING: the database connection string.
- DATABASE_ID: a database ID
Once connected, you can create and read data, for example:
db.pages.insertOne({ message: "Hello World!"})
db.pages.find({})
exit
What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[null,null,["Last updated 2025-08-25 UTC."],[],[],null,["\u003cbr /\u003e\n\n\n|--------------------------------------------------------|\n| *Relevant to Cloud Firestore Enterprise edition only.* |\n\n\u003cbr /\u003e\n\nLearn how to create a Cloud Firestore with MongoDB compatibility database and connect to it with the\n`mongosh` tool.\n\nBefore you begin\n\n1. If you haven't already, create a Firebase project: In the [Firebase console](//console.firebase.google.com/), click **Add project** , then follow the on-screen instructions to create a Firebase project or to add Firebase services to an existing Google Cloud project.\n2. [Install the `mongosh` tool](https://www.mongodb.com/docs/mongodb-shell/install/)\n\n\u003cbr /\u003e\n\nCreate a Cloud Firestore with MongoDB compatibility database and retrieve the connection string In the Firebase console, create a new Firestore Enterprise edition database. Cloud Firestore with MongoDB compatibility requires Firestore Enterprise edition:\n1. In the Firebase console, go to the **Firestore Database** page.\n\n [Go to Firestore Database](//console.firebase.google.com/project/_/firestore/databases/-default-/data/)\n2. Click the database that you want to authenticate.\n3. In the **Explorer** panel, click more_vert **View more**.\n4. Select **Connect using MongoDB tools**.\n5. Copy the connection string.\n\n\u003cbr /\u003e\n\nThe connection string depends on the UID of the database (system-generated)\nand the location of database: \n\n```text\nUID.LOCATION.firestore.goog\n```\n\nCreate a user for SCRAM authentication\n\nIn the Google Cloud console, create a new database user and assign\nthe user Identity and Access Management permissions.\n\n1. In the Google Cloud console, go to the **Databases** page.\n\n [Go to Databases](https://console.cloud.google.com/firestore/databases)\n2. Select the database from the list of databases.\n3. In the navigation menu, click **Auth**.\n4. Click **Add User**.\n5. Enter a username.\n6. Select an Identity and Access Management role for the user.\n7. Click create. The database creates a user and shows you the user's generated password. **Copy and save this password. You will not be able to retrieve\n this password later.**.\n\nConnect using `mongosh`\n\nUse the connection string, username, and password to connect to your\ndatabase, run `mongosh` locally with the following configuration options. \n\n```gdscript\nmongosh 'mongodb://\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e:\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e@\u003cvar translate=\"no\"\u003eCONNECTION_STRING\u003c/var\u003e:443/\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e?loadBalanced=true&authMechanism=SCRAM-SHA-256&tls=true&retryWrites=false'\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: the name of the database user you created.\n- \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: the generated password for the database user you created.\n- \u003cvar translate=\"no\"\u003eCONNECTION_STRING\u003c/var\u003e: the database connection string.\n- \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: a database ID\n\nOnce connected, you can create and read data, for example: \n\n```text\ndb.pages.insertOne({ message: \"Hello World!\"})\ndb.pages.find({})\nexit\n```\n\nWhat's next\n\n- [See a list of supported features](/docs/firestore/enterprise/supported-data-types-drivers)\n- [Learn about behavior differences in Cloud Firestore with MongoDB compatibility](/docs/firestore/enterprise/behavior-differences)\n- [Learn about additional authentication methods](/docs/firestore/enterprise/connect)"]]