当我从文件 A 导出模块并导入文件 B 时,我收到此错误,当我运行文件 B 时,它给出了该错误。这与 Firebase 云 Firestore 相关。
const mailEvents = (startTime, endTime) => {
serverRef = db.collection("MailEvents");
let getDocs = serverRef
.where("timestamp", ">=", startTime)
.where("timestamp", "<=", endTime)
.get()
.then(querySnapshot => {
if (querySnapshot) {
let docs = querySnapshot.docs.map(doc => doc.data());
console.log(docs)
}
});
}
mailEvents();
module.exports.mailEvents = mailEvents;
main.js 文件是
const module = require('./report.js')
module.mailEvents(1575225929,1575305012);
最佳答案
问题在于,在您的模块中,在导出之前,您调用了不带任何参数的 mailEvents()
函数,因此出现错误“无法使用“未定义”作为 Firestore 值”,因为它是尝试使用未定义的 startTime
和 endTime
查询集合。换句话说,每次需要此文件时,实际上都会调用该方法两次。您还可以在此处简化几行。如果您将该文件更改为以下内容,它应该可以工作:
const mailEvents = (startTime, endTime) => {
db.collection("MailEvents")
.where("timestamp", ">=", startTime)
.where("timestamp", "<=", endTime)
.get()
.then(querySnapshot => {
if (querySnapshot && querySnapshot.length > 0) {
let docs = querySnapshot.docs.map(doc => doc.data());
console.log(docs)
}
});
};
module.exports = {
mailEvents
};
关于javascript - 错误 : Value for argument "value" is not a valid query constraint. 无法使用 "undefined"作为 Firestore 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59505269/