[TOC] ## 概述 `>mongofiles.exe -d gridfs put song.mp3 ` -d 指定数据数据库 文件存储在两个集合中 - files - chunks # 操作 ### 添加文件 `mongofiles.exe -d gridfs put song.mp3` ### 查看文件信息 通过 files 集合查看文件信息 ``` db.fs.files.find() { _id: ObjectId('534a811bf8b4aa4d33fdf94d'), filename: "song.mp3", chunkSize: 261120, uploadDate: new Date(1397391643474), md5: "e4f53379c909f7bed2e9d631e15c1c41", length: 10401959 } ``` ### 下载文件 通过chuncks 查看文件资源 ``` db.fs.chunks.find({files_id:ObjectId('534a811bf8b4aa4d33fdf94d')}) // 1 { "_id": ObjectId("5e0b19161da03d479f008af0"), "files_id": ObjectId("5e0b19151da03d479f008aef"), "n": NumberInt("0"), "data": BinData(0, "TVqQAAMABAAAAAAA//8ABIjWwkMDHA6xNIjTWd......") } // 2 { "_id": ObjectId("5e0b19161da03d479f008af1"), "files_id": ObjectId("5e0b19151da03d479f008aef"), "n": NumberInt("1"), "data": BinData(0, "TVqQAAMABAAAAAAA//8A1231BIjW131wkMDHA6xNIjTWd......") } .... ```