title: trying to add an item in the Firestore collection after checking condition that the item does not already exists .if does increasing the quantity else
body: <p>trying to add an item in the Firestore collection after checking the condition that the item does not already exist.if it does exist increase the quantity of the item else add the new item with quantity 1.</p>
  <pre><code>function addToCart(item) {
  console.log(item)
  let cartItem = db.collection('cart-items').doc(item.id)
  
  cartItem.get()
      .then((doc) =&gt; {
          if (doc.exists) {
              cartItem.update({
                  quantity: doc.data().quantity + 1
              })
          }
          else {
              cartItem.set({
                  image: item.image,
                  make: item.make,
                  name: item.name,
                  rating: item.rating,
                  price: item.price,
                  quantity: 1
              })
          }
      })
  </code></pre>
  <p>}</p>