I have a set of objects in a mongodb database that have measurements embedded. I’m trying to do a map/reduce to get stats about the measurements. Well I ran into some problems with that so I just made it as simple as possible: get the number of measurements for each one.
m = function() {
emit (mp, { meas: this.measurements });
};
r = function() {
return { count: meas.length };
};
res = db.meas_points.mapReduce(m, r,
{query : { measurements : {$exists: true}}},
{out: { "measurements_stats" }} );
When I run this query I get an error:
Mon Jan 2 16:05:53 SyntaxError: missing : after property id (shell):1
I’m trying to see what this means in the context of my map/reduce but I’m just not seeing it. I lifted the code from the mongodb website ( http://www.mongodb.org/display/DOCS/MapReduce Shell Example 2) and adapted it to my needs. Seems like I’m doing everything right but I keep getting this cryptic error. I’m not using the id field at all — is it possible that I have a malformed record or something?
In this line
It is not able to resolve
measYou need to modify the signature of the reduce function.Here
measValuespassed to this reduce function itself is an arrayNote: If
mpin the map function is the id/key of your collection meas_points then change that line tothis.mp