我有以下pymongo代码:
import pymongo
import time
start_time = time.time()
connection_string = 'mongodb://localhost'
connection = pymongo.MongoClient(connection_string)
database = conn
pipe = [
*some code here*
]
start_time = time.time()
query = list(database.solution3.aggregate(pipe,allowDiskUse=True))
print("--- %s seconds ---" % (time.time() - start_time))
执行此查询后,我如何知道它的大小?
如果您检查query
列表的字符串表示形式的长度,您将获得列表中的字节数。
试试:
print(f'Length/size of query is --> {len(str(query))}')
您可以通过将其写入磁盘并在文件查看器中检查大小来验证(当然,编写列表的字符串表示形式和列表的字符串表示形式的长度应该相同(。
简单如下:
with open('<path to and file name>', 'w') as f:
f.write(str(query))