0

in my web app I query a Firestore database to enum orders.
This is working but I need to access to the ID of each order.

// Get Data
var resRef = firebase.firestore().collection("orders");
resRef.get().then( (orderList) => {

    orderList.forEach(
        function(order){
            console.log("order ID: ", order.?? )
            ...
        }
    )
    ...

How can I achieve that?

SteMMo
  • 392
  • 1
  • 4
  • 23

1 Answers1

0

The ID of each document is available as order.id. So:

var resRef = firebase.firestore().collection("orders");
resRef.get().then( (orderList) => {

    orderList.forEach(
        function(order){
            console.log("order ID: ", order.id )
            ...
        }
    )

Also see the Firebase documentation on getting documents from a collection.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807