The document describes MongoDB's GridFS specification for storing and retrieving files that exceed the BSON document size limit of 16MB. It explains that GridFS splits files into chunks, which are stored as individual documents, and maintains metadata about the file such as length, MD5, and filename in a separate collection. It provides examples of using the mongofiles command line tool to list, search, put, and get files from GridFS.
15. ➜ ~ mongofiles --help
usage: mongofiles [options] command [gridfs filename]
command:
one of (list|search|put|get)
list - file
search - file
put - file
get - file
delete - file
16. ➜ ~ mongofiles list
connected to: 127.0.0.1
➜ ~ mongofiles put ByeForNow.mp3
connected to: 127.0.0.1
added file: { _id: ObjectId('4df17f8d9d47ba5c0247e72e'),
filename: "ByeForNow.mp3", chunkSize: 262144, uploadDate:
new Date(1307672462538), md5:
"9ee9472200a2e18bf376ce622c3b0055", length: 11183104 }
done!
➜ ~ mongofiles list -v // -v
Fri Jun 10 11:21:05 creating new connection to:127.0.0.1
Fri Jun 10 11:21:05 BackgroundJob starting:
connected to: 127.0.0.1
ByeForNow.mp3 11183104
17. ➜ ~ mongofiles put Maria.mp3
connected to: 127.0.0.1
added file: { _id: ObjectId('4df181fc5e354129e833193f'),
filename: "Maria.mp3", chunkSize: 262144, uploadDate: new
Date(1307673086293), md5:
"9d4f424fa1843711e196e502d8a00183", length: 12225353 }
done!
➜ ~ mongofiles list
connected to: 127.0.0.1
ByeForNow.mp3 11183104
Maria.mp3 12225353
➜ ~ mongofiles list M
connected to: 127.0.0.1
Maria.mp3 12225353
➜ ~ mongofiles search .mp3
connected to: 127.0.0.1
ByeForNow.mp3 11183104
Maria.mp3 12225353
18. ➜ ~ mkdir tmp // get
➜ ~ cd tmp
➜ mongofiles get Maria.mp3
connected to: 127.0.0.1
done write to: Maria.mp3
➜ ls
Maria.mp3
➜ mongofiles get Bye
ERROR: file not found
➜ mongofiles get ByeForNow.mp3
done write to: ByeForNow.mp3
➜ md5 Maria.mp3
MD5 (Maria.mp3) = 9d4f424fa1843711e196e502d8a00183
➜ md5 ../Maria.mp3
MD5 (../Maria.mp3) = 9d4f424fa1843711e196e502d8a00183
70. r = function(key, values) {
var result = { age: 0, num: 0 };
values.forEach( function(value){
result.age += value.age; // age
result.num += value.num; //
} );
return result;
}
71. r = function(key, values) {
var num = 0;
var sum = 0;
values.forEach( function(value){
sum += value.age; // age
num += value.num; //
} );
return sum/num;
}
72. m = function() {
emit(this.type, { age: this.age, num: 1 } );
}
r = function(key, values) {
var result = { age: 0, num: 0 };
values.forEach( function(value){
result.age += value.age; // age
result.num += value.num; //
} );
return result;
}