Guest User

Untitled

a guest
May 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. // A simple grouping of Assets that mirror GridFS documents
  2. db.system.js.save(
  3. { _id: 'assetSizeBuckets',
  4. value: function() {
  5. return db.assets.group({
  6. keyf: function(asset) {
  7. if(asset.file_size < 10000) {
  8. return {small: true}
  9. } else if(asset.file_size < 100000) {
  10. return {medium: true}
  11. } else {
  12. return {large: true}
  13. }
  14. },
  15. initial: {tsize: 0.0, count: 0},
  16. reduce: function(asset,memo){
  17. memo.count++;
  18. memo.tsize += asset.file_size;
  19. },
  20. finalize: function(out){ out.avg_size = out.tsize / out.count }
  21. });
  22. }
  23. }
  24. );
  25.  
  26. // Where an Asset is a document like this:
  27. {
  28. "_id" : ObjectId("4be2f7ac80faa9d88e000005"),
  29. "file_name" : "some_file.html",
  30. "file_size" : 16849,
  31. "file_type" : "text/html",
  32. "file_id" : ObjectId("4be2f7ac80faa9d88e000006")
  33. }
Add Comment
Please, Sign In to add comment