Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A simple grouping of Assets that mirror GridFS documents
- db.system.js.save(
- { _id: 'assetSizeBuckets',
- value: function() {
- return db.assets.group({
- keyf: function(asset) {
- if(asset.file_size < 10000) {
- return {small: true}
- } else if(asset.file_size < 100000) {
- return {medium: true}
- } else {
- return {large: true}
- }
- },
- initial: {tsize: 0.0, count: 0},
- reduce: function(asset,memo){
- memo.count++;
- memo.tsize += asset.file_size;
- },
- finalize: function(out){ out.avg_size = out.tsize / out.count }
- });
- }
- }
- );
- // Where an Asset is a document like this:
- {
- "_id" : ObjectId("4be2f7ac80faa9d88e000005"),
- "file_name" : "some_file.html",
- "file_size" : 16849,
- "file_type" : "text/html",
- "file_id" : ObjectId("4be2f7ac80faa9d88e000006")
- }
Add Comment
Please, Sign In to add comment