Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cloud/03 Data Persistence.md
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (47 sloc)
1.68 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data Persistence | |
```shell | |
$ firebase init database | |
? What file should be used for Database Rules? (database.rules.json) | |
? File database.rules.json already exists. Do you want to overwrite it | |
with the Database Rules for from the Firebase Console? (y) | |
✔ Database Rules for have been downloaded to database.rules.json. | |
Future modifications to database.rules.json will update Database Rules | |
when you run firebase deploy. | |
i Writing configuration info to firebase.json... | |
i Writing project information to .firebaserc... | |
✔ Firebase initialization complete! | |
``` | |
Now you will need to log onto the firebase console for your app and make the following changes: | |
1. Access the **Database** tab and click on the **Create database** button. | |
2. Choose to _start in production mode_. | |
3. For region choose _eur3 (europe-west)_. | |
4. Wait for the provisioning process to complete. | |
At present the permissions are restrictive and prevent anyone from adding or viewing the documents. Access the **Rules** tab and change the rules to the following: | |
```javascript | |
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /{document=**} { | |
allow read, write: if request.auth != null; | |
} | |
} | |
} | |
``` | |
This gives any logged in user read/write access to all documents. | |
``` | |
// allow any authorised user to read and write the documents | |
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /{document=**} { | |
allow read, write: if request.auth != null; | |
} | |
} | |
} | |
``` | |
```javascript | |
// updating a record | |
db.collection('todo') | |
.doc('qIIz49uGTyHg737BYNSP') | |
.update({ | |
title: "JavScript MVC Design Pattern" | |
}) | |
``` |