javascript - How to use scope variables as property names in a Mongo Map/Reduce emit -
there question (and answer) deals general case. having difficulty using scope variable field key (as opposed field value)
in example below fully_caps fields scope variables. in case of service , identifier emit correctly uses value of scope variable passed m/r.
however when try use value of scope variable key in emitted document, document created scope variable name (as opposed it's value).
return emit({ service: service, date: _this.value.date, identifier: _this.value[identifier] }, { errors: { count: 1, type_breakdown: { singles_only: { count: 1 } } } });
is there way around problem?
when using shortcut syntax creating objects in javascript, left hand side/property name interpreted literal value, regardless of quotes.
for example:
var d={ name: "aaron" }
is equivalent to:
var d={ "name" : "aaron" }
as there 2 ways set property value:
obj.propertyname=value
obj["propertname"]=value
you have construct object using second syntax, @ least in part.
var errors={ count: 1, type_breakdown: { } } }; var countobj={ count:1 }; errors.type_breakdown[singles_only]=countobj; // pass results emit call
Comments
Post a Comment