From d8e46419b18418c7e06e629f4acfeed6a79020a5 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Sat, 1 Jun 2013 00:16:04 +0200 Subject: [PATCH] Make the javascript code more redeable --- database.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/database.go b/database.go index 47d1863..ea03fd0 100644 --- a/database.go +++ b/database.go @@ -208,14 +208,16 @@ func (d *DB) updateTags() error { } var mr mgo.MapReduce - mr.Map = "function() { " + - "if (this.active) { this.subject.forEach(function(s) { emit(s, 1); }); }" + - "}" - mr.Reduce = "function(tag, vals) { " + - "var count = 0;" + - "vals.forEach(function() { count += 1; });" + - "return count;" + - "}" + mr.Map = `function() { + if (this.active) { + this.subject.forEach(function(s) { emit(s, 1); }); + } + }` + mr.Reduce = `function(tag, vals) { + var count = 0; + vals.forEach(function() { count += 1; }); + return count; + }` mr.Out = bson.M{"replace": TAGS_COLL} _, err = d.books.Find(bson.M{"active": true}).MapReduce(&mr, nil) if err != nil {