How can I know if docs is empty? I can\'t do len(docs)
docs = query.stream()
for doc in docs:
// do something
I need to know i
Since stream()
returns a generator, there won't be a trivial way to determine if it is empty without actually reading it.
By far the simplest solution would delay knowing until after you are past the loop. Something like this:
docs = query.stream()
stream_empty = True
for doc in docs:
stream_empty = False
# do something
if stream_empty:
print("it was empty")
else:
print("it wasn't empty")
Otherwise, you get into having to build your own generator around the stream's generator that allows peeking. See this question.