Guest User

Untitled

a guest
Jan 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. models.defineModels(mongoose, function() {
  2. app.Movie = Movie = mongoose.model('Movie');
  3. db = mongoose.connect(app.set('db-uri'));
  4. mongoose.connection.on('open', function() {
  5. map();
  6. });
  7. })
  8.  
  9.  
  10. function map() {
  11. m = function() {
  12. this.q = this.q.replace(/_|-/g, ' ')
  13. emit(this.q, {count: 1, type: this.type});
  14. };
  15.  
  16. r = function(key, vals) {
  17. var result = {count: 0, type: vals.type}
  18.  
  19. vals.forEach(function(val) {
  20. result.type = val.type;
  21. result.count += val.count;
  22. });
  23. return result;
  24. };
  25.  
  26. var cmd = {
  27. mapreduce: "queries",
  28. query: {},
  29. map: m.toString(),
  30. reduce: r.toString(),
  31. out: "trends"
  32. };
  33.  
  34. mongoose.connection.db.executeDbCommand(cmd, function(err, dbres) {
  35. console.log(err);
  36. console.log(dbres);
  37. process.exit();
  38. });
  39. };
Add Comment
Please, Sign In to add comment