Python3操作MongoDB存储图片

推荐阅读

from io import BytesIO

import bson
import pymongo
import requests

conn = pymongo.MongoClient(host='127.0.0.1', port=27017)
db = conn.数据库名
collection = db.表名

img = BytesIO(requests.get(url='图片链接').content)
collection.save(dict(_id='ID', img=bson.binary.Binary(img.getvalue())))

conn.close()