Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time

Data Persistence

$ 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:

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"     
  })