Cloud Firestore
Store, sync, and query app data with Cloud Firestore for your Golex web app
Overview
Cloud Firestore is a flexible, scalable NoSQL cloud database that lets you store and sync data across your web app users in real-time. With Golex’s Firebase integration, your app will automatically connect to Firestore once it’s enabled, allowing you to build powerful data-driven features with minimal effort.
Before You Begin
Make sure you’ve completed the Firebase Setup guide before enabling Firestore.
Step 1: Enable Cloud Firestore in Firebase Console
To start using Firestore in your Golex app, you first need to enable it in the Firebase Console:
- Go to the Firebase Console
- Select your project
- In the left sidebar, click on Firestore Database
- Click the Create database button
Choose Security Rules Mode
You’ll be prompted to choose your security rules starting mode:
- Production mode: Denies all reads and writes by default. This is more secure but requires you to explicitly define security rules.
- Test mode: Allows all reads and writes from any user for 30 days. This is convenient for development but not secure for production.
For beginners, you can select Test mode to get started quickly, but remember to update your security rules before deploying to production.
Choose a Location for Your Database
Select a geographical location for your Firestore database. Consider choosing a region that’s close to your target users for better performance.
Click Enable to create your Firestore database.
Step 2: Automatic Connection to Your Golex App
Once Firestore is enabled in your Firebase project, your Golex app will automatically detect and connect to it when you’ve properly connected Firebase to your Golex app.
There’s no additional configuration needed — your app is ready to use Firestore for data storage!
Step 3: Using Firestore in Your Golex App
Golex makes it easy to implement Firestore features in your app using prompt-driven development:
Adding Firestore Features via Prompts
Example prompts:
- “Create a form that saves user feedback”
- “Show a list of products from the database”
- “Add a real-time chat feature using database”
- “Create a user profile page that displays and updates user data”
Golex will generate the necessary components and logic to implement these features, with the appropriate Firestore calls already integrated.
Common Firestore Operations
Golex can help you implement these common Firestore operations:
- Create: Add new documents to collections
- Read: Retrieve single documents or query collections
- Update: Modify existing documents
- Delete: Remove documents from collections
- Real-time updates: Listen for data changes in real-time
Security Rules
With Golex, you can easily define granular security rules to protect your Firestore data. Instead of manually configuring rules in the Firebase Console, simply tell Golex what access patterns you want, and it will automatically generate and deploy the appropriate security rules.
For example, you can specify rules like:
- Only authenticated users can read data
- Users can only edit their own profile data
- Task creators can edit/delete their tasks, while others can only view them
- Admin users have full access to all collections
Setting Up Security Rules with Golex
Simply use natural language to describe your security requirements:
“I want tasks to only be editable by their creator, but readable by all authenticated users”
Golex will automatically:
- Generate the appropriate Firestore security rules
- Deploy them to your Firebase project
- Validate the rules are working as expected
Important Security Note
Always specify your security requirements before deploying to production. The default test mode allows unrestricted access and should never be used in production environments.
Example Security Pattern
Here’s how you might tell Golex to set up task-based security:
“For my tasks collection:
- Only authenticated users can read tasks
- Only the task creator can edit or delete their tasks
- Users can create new tasks
- Each task must have a createdBy field matching the user’s ID”
Golex will handle all the complex security rule generation and deployment automatically, ensuring your data remains secure according to your specifications.