0

I'm trying to read data from my Firestore database in my cloud functions.

My Database:

cases -> 1 -> (number) min: 1

My code in my function https.onCall( async (data, context):

if(!data.caseslot) {
        console.log("no caseslot");
        //throw exception
    }
    else{
        console.log(data.caseslot); //this logs me 1
        var db = admin.firestore();
        db.collection('cases').doc('${data.caseslot}').get().then(snapshot => {
            console.log(snapshot.data().min); //"TypeError: Cannot read properties of undefined (reading 'min')"
        }).catch(reason => {
            console.log(reason);
        });
    }

At this point, I don't know what I'm doing wrong. I double checked my database...

1 Answer 1

1

You have enclosed ${data.caseslot} in single quotes, you have to enclose that in back ticks

if (!data.caseslot) {
  console.log("no caseslot");
  //throw exception
} else {
  console.log(data.caseslot);
  var db = admin.firestore();
  db.collection("cases")
    .doc(`${data.caseslot}`) //enclose in back ticks (``)
    .get()
    .then((snapshot) => {
      console.log(snapshot.data().min);
    })
    .catch((reason) => {
      console.log(reason);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.