GridFS是mongodb存储大容量二进制文件的机制。
注:GridFS中chunk和Sharding中的chunk不是同一种意义上的chunk。
GridFS存储的Collection:
数据存储的collection: 每个数据库的 fs.chunks
元数据存储的collection: 每个数据库的 fs.files
mongofiles命令:
mongofiles 是用来操作GridFS的命令工具
- –db //指定database
- –local,-l //指定本地输出(get)/输入(put)文件名
- –replace, -r //替换GridFS中已存在的文件, 与put方法一起使用
- –writeConcern “{w:’majority’}” //
可用的方法:list, put, get, delete, get_id, delete_id

Hashed shard key for GridFS
GirdFS的_id天生为一个Ascending shard key。在shard set集群中,为了更好的让数据分布平衡。可以通过hased shard key 处理_id,使GridFS的数据分布平衡。
db.fs.chunks.createIndex({“files_id” : “hashed“})
sh.shardCollection(“test.fs.chunks”, {“files_id” : “hashed“})

