import pymongo
import os
client = pymongo.MongoClient(host = 'localhost', port = 27017)
path = r'E:/保标/Log/'
db = client.log
for root,filedir,filenames in os.walk(path):
collection = db[root]
files = [root +'/' + filename for filename in filenames]
for file in files:
data = open(file, 'r')
col = {file.replace('.','/'): list(data)}
collection.insert(col)
如何将txt文件转储为 mongodb中的bson文件
最新推荐文章于 2022-10-24 10:10:07 发布