javascript - 在 firestore 中使用 whereGreaterThanOrEqualTo 时出错
问题描述
使用 firebase 的 whereGreaterThanOrEqualTo 时出现错误。我想要做的是搜索我的数据库,如果它以相应的字母开头,这是我的代码:
constructor(fireStore, rootStore) {
this._firestore = fireStore;
this._employeeInfo = this._firestore.collection('Employee');
}
getEmployeeInfo = async () => {
const employeeList = [];
const snapshot = await this._employeeInfo
.whereGreaterThanOrEqualTo("fullName", this.fullName)
.get()
snapshot.docs.forEach((doc) => {
employeeList.push(doc.data());
});
return employeeList;
};
错误是
"TypeError: _this2._employeeInfo.whereGreaterThanOrEqualTo is not a function. (In '_this2._employeeInfo.whereGreaterThanOrEqualTo("fullName", _this2.fullName)', '_this2._employeeInfo.whereGreaterThanOrEqualTo' is undefined)"
解决方案
您正在使用 Javascript,因此您需要以这种方式使用它:
this._employeeInfo.where("fullName", '>=', this.fullName)
以下是可用比较运算符的列表以及不同语言的示例:https ://firebase.google.com/docs/firestore/query-data/queries#query_operators
如文档中所述:仅“对于 iOS、Android 和 Java,比较运算符在方法中显式命名。”
旁注:如果您尝试模拟一种自动完成样式,您最好使用https://firebase.google.com/docs/reference/js/firebase.database.Query#startat而不是进行字符串比较。
像这样的东西应该工作:
this._employeeInfo.orderBy("fullName").startAt(searchText).endAt(searchText + "\uf8ff");
推荐阅读
- symfony - 尝试使用 Swiftmailer 加载类“Swift_Attachment”
- php - Quickbooks 错误:属性 IsProject 不存在。IPPCustomer 类
- omnet++ - 是否有可能在 Veins 中使用当前的夜间版本的 SUMO?
- java - 将数据从 Java 进程传递到 python 脚本
- plantuml - PlantUML,列重排
- tensorflow - Keras 自定义损失:我如何知道哪些模式对应于 y_pred 和 y_true?
- c - 无法在 C 中打开文件 - 在 C 中打开文件时出错
- python - 在一个图中绘制不同数据框的不同列作为散点图
- spring-boot - 没有服务层的springboot项目
- android - 在 Unity 应用程序中初始化 Firebase 时出现 Native NullPointerException