php - 在云 Firestore 和 php 中查询
问题描述
我想在 Firestore 中进行查询,但收到此错误
Undefined method 'orderBy'.
我的编码是
$collectionReference = $db->collection('Test3')->document('User1');
$query = $collectionReference->orderBy('Name')->limit(1);
$snapshot = $query->snapshot();
为什么会这样?
解决方案
您$collectionReference
的不是 CollectionReference;这是一个文档参考(因此是->document('User1')
)。
->orderBy
适用于 COLLECTION 查询。 如果您尝试获取需要使用的“Test3”集合:
$collectionReference = $db->collection('Test3');
$query = $collectionReference->orderBy('Name')->limit(1);
$snapshot = $query->snapshot();
我也没有看到->get()
- 我不再使用 PHP,所以我不知道它是否隐含在语法中。
推荐阅读
- angular - 无法绑定到“ngForOf”,因为在子模块的组件中访问 *ngFor 时它不是“div”的已知属性
- javascript - 关于 concole.log 中显示错误时的行为
- python - 如何在列表列表中生成随机数
- python - 如何检查处理 Celery 任务的队列
- bash - 用于取消当前(以及所有后续)脚本的 Bash 退出选项
- node.js - “ReplyError: ERR unkown command 'json.set' ? 使用 redis rejson, google oauth
- amazon-web-services - 具有定义持续时间的现场实例和多种实例类型的 AWS Auto Scaling 组
- unity3d - 全息远程无法统一捕捉手势
- python - 将字典理解的每次迭代存储在新的嵌套字典中
- java - java如何使用服务帐户将文件夹创建到共享驱动器中进行身份验证