I have a function map created, is this
var m = function() {
hashtags = {}
for(var i in this.entities.hashtags) {
hashtags[this.entities.hashtags[i].text] = 1
};
var valor = {numtweets: 1 ,
dic_hastag: hashtags};
print(" value: " + tojson(valor));
emit(this.place.country_code, valor)
};
I start from a collection called tweets, and the output of my map function should have a variable numtweets: 1 and av ariable hastags with the entire list of tweet hastats with a 1. example Nuwtweets: 1, hastags: "hast1": 1, "hast2": 2, "hast3": 1 1.- I can have the result saved in a collection, to prove that it works well instead of print 2.- If not if I have to do mapreduce, what should be the function reduces, why not do anything, and so when executing this, the output of the map function
Db.runCommand ({
MapReduce: "tweets",
Map: m,
Reduce: r,
Query: {"place.country_code": "AD"},
Out: {replace: "resultat5fi"}
});
Any suggestions, help, anything will be welcome.
I suggest you to see this .
This the way to debug map functions easily with mongodb.
first, create your map function as you did
Then define an emit function that will print (or insert into a collection)
Example of emit function that insert into a toto collection.
var emit = function(key, value) {
db.toto.insert({key: key, value: value});
}
Example :
var myCursor = db.tweets.find( {} );
while (myCursor.hasNext()) {
var doc = myCursor.next();
map.apply(doc);
print();
}
This way :
db.toto.find()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.