Spring-Data-MongoDB passing scope variables to map\reduce:
It's becoming a little bit tricky if you want to pass something like wrapper that contains Map of Map's as a parameter to map\reduce.
Anyhow, If you'll find yourself in trouble passing parameters to map\reduce here is one way to handle it:
ObjectMapper is a Jackson framework class.
It's becoming a little bit tricky if you want to pass something like wrapper that contains Map of Map's as a parameter to map\reduce.
Anyhow, If you'll find yourself in trouble passing parameters to map\reduce here is one way to handle it:
MapReduceOptions options = MapReduceOptions.options();this way scope parameter will be passed as a pure JSON map object, which will be automatically mapped to js object by MongoDB.
Map vars = new HashMap();
try {
ObjectMapper mapper = new ObjectMapper();
DBObject dbo = new BasicDBObject(mapper.convertValue(myobject, Map.class));
vars.put("myparamName",dbo);
} catch (Exception e) {
logger.error(e);
}
options.scopeVariables(vars);
ObjectMapper is a Jackson framework class.
No comments:
Post a Comment