DEV Community

Cover image for CRUD in Firebase
ARUN KRISHNAN K
ARUN KRISHNAN K

Posted on

CRUD in Firebase

CRUD operation in Firebase using react and javascript


        // Read
        db.collection('products').get().then(resposne=>{
          resposne.forEach((object)=>{
            console.log(object.data(),object.id);
          })
        })

        // Create
        db.collection('products').add({
          name: 'Laptop',
          type: 'Electronics',
          price: 50000
        }).then(()=>{
          console.log('Added');
        })

        // Delete
        db.collection('products').doc('Q4tjiYSC05MjYG6pQBIQ').delete().then(()=>{
          console.log('Deleted');
        })

        // Update
        db.collection('products').doc('BDgu0r6ECRtyUKxxkxcs').update({
          name: 'Laptop',
          type: 'Electronics',
          price: 50
        }).then(()=>{
          console.log('Updated');
        })

Enter fullscreen mode Exit fullscreen mode

Top comments (0)