python使用pymongo和gridfs将mongodb图像与文本合并

python使用pymongo和gridfs将mongodb图像与文本合并,python,mongodb,pymongo,gridfs,Python,Mongodb,Pymongo,Gridfs,现在我创建要插入的函数 import pymongo from pymongo import MongoClient import gridfs password="pass" cluster=MongoClient(f'mongodb+srv://db:{password}@cluster0.4frlm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority') db=cluster["db&qu

现在我创建要插入的函数

import pymongo
from pymongo import MongoClient
import gridfs

password="pass"
cluster=MongoClient(f'mongodb+srv://db:{password}@cluster0.4frlm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')

db=cluster["db"]
collection=db["post"]

#Create an object of GridFs for the above database.
fs = gridfs.GridFS(db)
我只想将它们插入相同的元组或帖子中,就像我将拥有的每个条目一样:
{id、编号、标题、图像}

def post_scrap(post_id):

    title=title_scrap(post_id)
    title=number_scrap(number)

    post={"_id":post_id,"title":title}
    
    image = f'{post_id}.jpg'
    with open(image, 'rb') as i:
        im= i.ead()
        
    fs.put(im filename=post_id)
    collection.insert_one(post)