pymongo - 消息长度大于服务器最大消息大小 [英] pymongo - Message length is larger than server max message size

查看:82
本文介绍了pymongo - 消息长度大于服务器最大消息大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for doc in collection.find({'is_timeline_valid': True}): 给出了消息长度错误.如何在没有错误的情况下获取所有集合?我知道 find().limit() 但我不知道如何使用它.

the line for doc in collection.find({'is_timeline_valid': True}): is giving the Message Length error. How can I get all the collection without the error? I know about the find().limit() but I don't know how to use it.

代码:

from openpyxl import load_workbook
import pymongo
import os

wb = load_workbook('concilia.xlsx')
ws = wb.active
client = pymongo.MongoClient('...')
db = client['...']
collection = db['...']

r = 2
for doc in collection.find({'is_timeline_valid': True}):
   for dic in doc['timeline']['datas']:
     if 'concilia' in dic['tramite'].lower():
        ws.cell(row = r, column = 1).value = doc['id_process_unformatted']
        ws.cell(row = r, column = 2).value = dic['data']
        ws.cell(row = r, column = 3).value = dic['tramite']
        wb.save('concilia.xlsx')
        print('*****************************')
        print(dic['tramite'])
        # print('check!')
        r += 1

推荐答案

我们可以在 find() 中添加 batch_size 来减小消息大小.

we can add batch_size to find() to reduce the message size.

for doc in collection.find({'is_timeline_valid': True}):

变成

for doc in collection.find({'is_timeline_valid': True}, batch_size=1):

这篇关于pymongo - 消息长度大于服务器最大消息大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆