Home > Back-end >  how to add nested collection in firebase v9?
how to add nested collection in firebase v9?

Time:01-04

// written for firebase v8 -->
db.collection("users")
          .doc(user?.id)
          .collection("orders")
          .doc(paymentIntent.id)
          .set({
            basket: basket,
            amount: paymentIntent.amount,
            created: paymentIntent.created,
          });

----> // How to write this same code for firebase v9?

CodePudding user response:

The equivalent in v9 would be:

const paymentRef = doc(db, "users", user?.id, "orders", paymentIntent.id);
setDoc(paymentRef, {
  basket: basket,
  amount: paymentIntent.amount,
  created: paymentIntent.created,
});
  • Related