$ 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:
- Access the Database tab and click on the Create database button.
- Choose to start in production mode.
- For region choose eur3 (europe-west).
- 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:
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;
}
}
}
// updating a record
db.collection('todo')
.doc('qIIz49uGTyHg737BYNSP')
.update({
title: "JavScript MVC Design Pattern"
})