我正试图对一些文件进行分页。当我运行第二个查询以获取项目(11-20)时,我在排除order_by时出现此错误。
引用:
Traceback (most recent call last):
File "firebase.py", line 30, in <module>
for video in second_page:
File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\google\cloud\firestore_v1beta1\query.py", line 583, in get
parent_path, self._to_protobuf(),
File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\google\cloud\firestore_v1beta1\query.py", line 546, in _to_protobuf
'start_at': _cursor_pb(self._start_at, self._orders),
File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\google\cloud\firestore_v1beta1\query.py", line 729, in _cursor_pb
raise ValueError(_NO_ORDERS_FOR_CURSOR)
ValueError: Attempting to create a cursor with no fields to order
on. When defining a cursor with one of ``start_at()`` / ``start_after()`` /
``end_before()`` / ``end_at()``, all fields in the cursor must come from
fields set in ``order_by()``.
代码:
chem_videos =
db.collection(u'subjects').document(u'chemistry').collection(u'Videos')
first = chem_videos.limit(10)
first_page = first.get()
last_video = list(first.get())[-1]
last_id = last_video.to_dict()[u'video_id']
这有效
second = chem_videos.order_by(u'video_id').start_after({u'video_id':last_id}).limit(10)
但这不是:
second = chem_videos.start_after(last_video).limit(10)
当我使用start_after时,是否绝对需要用户orber_by?