问题描述
Undefined method 'orderBy'.
我的编码是
$collectionReference = $db->collection('Test3')->document('User1');
$query = $collectionReference->orderBy('Name')->limit(1);
$snapshot = $query->snapshot();
为什么会这样?
解决方法
您的 $collectionReference
不是 CollectionReference;这是一个 DOCUMENT 引用(因此是 ->document('User1')
)。
->orderBy
适用于 COLLECTION 查询。 如果您正在尝试获取需要使用的“Test3”集合:
$collectionReference = $db->collection('Test3');
$query = $collectionReference->orderBy('Name')->limit(1);
$snapshot = $query->snapshot();
我也没有看到 ->get()
- 我不再使用 PHP,所以我不知道它是否隐含在语法中。