Mongodb MapReduce to concatenate strings?

It looks to me like you're trying to do a group-by via type. If so, you should be emitting type first. From there, its pretty much the same as your code, but I took the liberty of cleaning it up a bit.

It looks to me like you're trying to do a group-by via type. If so, you should be emitting type first. From there, its pretty much the same as your code, but I took the liberty of cleaning it up a bit.

Beware, the reduce function could get called multiple times on smaller groups. Therefore, if you used your code in a sharded environment, you may get extra trailing commas. See Reduce Function for more information.

Map: m = function(){ emit(this. Type, {names:this. Name}); } Reduce: r = function(key, values){ var all = ; values.

ForEach(function(x){ all. Push(x. Names) }) return {"names": all.

Join(", ")}; } Usage: res = db.users. MapReduce(m,r); dbres.result.find() Alternate: Per OP request, here is a version that returns an array for names instead of a comma separated list string: m = function () { emit(this. Type, {names:this.Name}); } r = function (key, values) { var all = ; values.

ForEach(function (x) {all. Push(x. Names);}); return {type:key, names:all}; } f = function (w, r) { r.

Names = r. Names0; return r } res = db.users. MapReduce(m,r, {finalize:f}); dbres.result.find() Cheers!

Simply putting in return {"names": all}; in the map function works but gets me a bunch of ugly nested arrays like 0 => Array ( 0 => Array ( 0 => Array ( 0 => Array ( 0 => Array ( 0 => Array ( – Jonathan Knight Jun 4 '10 at 21:14 Ahh... yeah. I wasn't sure what your intent was, so I guessed based on your code. I'll modify my answer to include an array example.

– Van Nguyen Jun 4 '10 at 21:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions