I'm making a MongoDB query where i both need to loop through my results and count the len of the result to see if i'm being returned an empty result.
Here is what i tried:
Record = db.mycol.find({"datetimeraw": dt.now().strftime('%Y%m%d%H%M')})
RecordLen = Record.count()
print('LEN IS':RecordLen)
for x in Record:
print(x)
This code works, but when i use it i get the following error: DeprecationWarning: count is deprecated. Use Collection.count_documents instead. The problem is that i cannot use count_documents(), since it will return an integer and not a list of results that i can loop through; i would have to make two queries in this case: one to count and one to retrieve the results, and i would like to avoid that. Is there any way to do this or can i only use a depecrated function?