# -*- coding: utf-8 -*-from __future__ import with_statementimport os,sys,shutil,threadingfrom time import ctimefrom pymongo import Connectionfrom gridfs import *def read():conn = Connection("2.2.2.13",30000)db = conn['virus']GridFS(db,'fs')mygfs = GridFS(db,'fs')tmpgfs = db ['fs.files']dir = "/pyApp/insert/files"n = 0while n < 100:for parent, dirnames, filenames in os.walk(dir):for filename in filenames:filePath = os.path.join(parent, filename)with open(filePath, "rb") as file:mygfs.put(file.read())n+=1def main():print 'start at:', ctime()read()print 'All done at:', ctime()if __name__ == '__main__':main()
Traceback (most recent call last):File "D:\pyApp\PutInto\T-Test\i3.py", line 38, in <module>main()File "D:\pyApp\PutInto\T-Test\i3.py", line 33, in mainread()File "D:\pyApp\PutInto\T-Test\i3.py", line 24, in readmygfs.put(file.read())File "C:\Python27\lib\site-packages\gridfs\__init__.py", line 116, in putgrid_file.close()File "C:\Python27\lib\site-packages\gridfs\grid_file.py", line 220, in closeself.__flush()File "C:\Python27\lib\site-packages\gridfs\grid_file.py", line 202, in __flushroot=self._coll.name)["md5"]File "C:\Python27\lib\site-packages\pymongo\database.py", line 340, in commandmsg, allowable_errors)File "C:\Python27\lib\site-packages\pymongo\helpers.py", line 126, in _check_command_responseraise OperationFailure(msg % response["errmsg"])pymongo.errors.OperationFailure: command SON([('filemd5', ObjectId('4f9919e83e06fa10040002a0')), ('root', u'fs')]) failed: exception: chunks out of order
> mongodb-user+unsubscribe@googlegroups.com.
mongos> db.printShardingStatus()--- Sharding Status ---sharding version: { "_id" : 1, "version" : 3 }shards:{ "_id" : "s1", "host" : "shard1/8.8.8.22:27017,8.8.8.23:27017" }{ "_id" : "s2", "host" : "shard2/8.8.8.22:27018,8.8.8.23:27018" }{ "_id" : "s3", "host" : "shard3/8.8.8.22:27019,8.8.8.23:27019" }databases:{ "_id" : "admin", "partitioned" : false, "primary" : "config" }{ "_id" : "virus", "partitioned" : true, "primary" : "s1" }virus.fs.chunks chunks:s2 3450s1 3450s3 3456too many chunks to print, use verbose if you want to force print{ "_id" : "db", "partitioned" : false, "primary" : "s1" }