python分配buffer

编程入门 行业动态 更新时间:2024-10-17 21:16:59

python<a href=https://www.elefans.com/category/jswz/34/1770682.html style=分配buffer"/>

python分配buffer

# 场景:一次取回mongodb某表-64万数据,pymongo.errors.DocumentTooLarge: BSON document too large (28888095 bytes) -

# the connected server supports BSON document sizes up to 16777216 bytes. 文档太大就无法返回,因此分10次取,每次

# 取回6400条,然后统一更新到本地的字典中。

import uuid

data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 6, 7, 8, 9, 6, 5, 4, 3, 8, 9]

batch_step = round(len(data)/10)

for index in range(0, len(data), batch_step):

item_list = data[index:index+batch_step]

# example

from pymongo import MongoClient

mdb = MongoClient('120.133.26.xxx:20002', username='xt', password='xxxxxx')

image_ids = ["001", "002", "003", ...]

image_dict = {}

batch_step = round(len(image_ids)/10)

for idx in range(0, len(image_ids), batch_step):

image_ids_part = image_ids[idx:idx + batch_step]

image_infos = mdb['数据库名']['图片表名'].find({"image_id": {"$in": image_ids_part}})

image_one = {}

for image_info in image_infos:

if image_info.get("image_size"):

image_one[image_info.get("image_id")] = image_info

image_dict.update(image_one)

更多推荐

python分配buffer

本文发布于:2024-03-07 23:26:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分配   python   buffer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!