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 mongoshtool
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. 
- Click the database that you want to authenticate.
- In the Explorer panel, click 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. 
- 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 

