Skip to content

Commit 22dcada

Browse files
author
tuntun
committed
使用python操作MongoDB的GridFS下载文件
1 parent b997789 commit 22dcada

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

testmongo.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1+
# -*- coding:utf-8 -*-
2+
13
from pymongo import MongoClient
2-
import gridfs
34
import time
45
import re
56
import os
7+
import gridfs
68
import sys
79

8-
client = MongoClient('mongodb://192.168.1.22:27017/excel')
10+
client = MongoClient('mongodb://m_user:m_user_027@192.168.5.22:27017/js_send_excel')
911
db = client.js_send_excel
1012
fs = gridfs.GridFS(db)
13+
1114
files = fs.find()
1215

1316
time_start = time.clock()
1417
print('总数:', files.count())
18+
count = 0
1519

1620
for ffle in files:
1721
filename = ffle.filename
22+
1823
m = re.match(r'发货订单', filename)
1924

20-
if m and filename.find('.xls') > 0 and not os.path.isfile('./excel/' + filename):
21-
with open('./excel/' + filename, 'wb') as f1:
25+
if m and filename.find('xls') > 0 and not os.path.isfile('./excel/' + filename):
26+
with open('./excel2/' + filename, 'wb') as f1:
2227
f1.write(ffle.read())
28+
count += 1
2329

24-
print('执行时间{0}秒'.format(time.clock() - time_start))
30+
print('执行时间{0}秒'.format(time.clock() - time_start))
31+
print('本次更新{0}个文档'.format(count))

0 commit comments

Comments
 (0)