Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- models.defineModels(mongoose, function() {
- app.Movie = Movie = mongoose.model('Movie');
- db = mongoose.connect(app.set('db-uri'));
- mongoose.connection.on('open', function() {
- map();
- });
- })
- function map() {
- m = function() {
- this.q = this.q.replace(/_|-/g, ' ')
- emit(this.q, {count: 1, type: this.type});
- };
- r = function(key, vals) {
- var result = {count: 0, type: vals.type}
- vals.forEach(function(val) {
- result.type = val.type;
- result.count += val.count;
- });
- return result;
- };
- var cmd = {
- mapreduce: "queries",
- query: {},
- map: m.toString(),
- reduce: r.toString(),
- out: "trends"
- };
- mongoose.connection.db.executeDbCommand(cmd, function(err, dbres) {
- console.log(err);
- console.log(dbres);
- process.exit();
- });
- };
Add Comment
Please, Sign In to add comment