Firebase 函数从 Firestore 数据库读取失败且没有错误

Firebase Functions Read from Firestore Database fails without an error

我正在尝试从我的云函数中的 Firestore 数据库中读取数据。

我的数据库:

案例 -> 1 -> (数量) 最小值:1

我的代码在我的函数中 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);
        });
    }

在这一点上,我不知道自己做错了什么。我仔细检查了我的数据库...

您已将 ${data.caseslot} 括在单引号中,您必须将其括在反引号中

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);
    });
}