当在 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/