gpt4 book ai didi

javascript - 当向我显示此错误 "Cannot read properties of undefined (reading ' _internalPath') 时,我尝试使用 nodejs 和 firestore 中的过滤器获取数据”

转载 作者:行者123 更新时间:2023-12-05 05:33:26 26 4
gpt4 key购买 nike

当在 postman 中显示此错误时,我尝试使用 nodejs 和 firestore 中的过滤器获取数据

"Cannot read properties of undefined (reading '_internalPath')"

我的代码

const getAllWords = async (req, res, next) => {
let categoryName = "fruits"

try {
const word = await firestore.collection('12words');
const data = await word.where({categoryName}).get();
const wordArray = [];
if(data.empty) {
res.status(404).send('No words12 found');
}else {
data.forEach(doc => {
const words = new Word12(
doc.id,
doc.data().name,
doc.data().categoryName,

);
wordArray.push(words);
});
res.send(wordArray);
}
} catch (error) {
res.status(400).send(error.message);
}
}

最佳答案

.where() 有 3 个参数 (fieldPath, opStr, value) 但你只传递了 1 个对象。尝试重构代码,如下所示:

// replace fieldName with the field name in document
const data = await word.where("fieldName", "==", categoryName).get();

关于javascript - 当向我显示此错误 "Cannot read properties of undefined (reading ' _internalPath') 时,我尝试使用 nodejs 和 firestore 中的过滤器获取数据”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73850393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com