mongodb spring-mongo mapreduce


String map = "function(){emit(this.requesterAccountName,this.amount);}";
    String reduce =
            "function(key, values){ var sum = 0; for(var i = 0; i<values.length;i++ )sum += values[i]; return sum; }";

    MapReduceResults<XObject> results = mongoOperations.mapReduce(
            Query.query(Criteria.where("requesterAccountName").is(requesterAccountName)),
            "requesterBill",
            map,
            reduce,
            // new MapReduceOptions().outputCollection("mr_out"),
            XObject.class);
    List<BasicDBObject> xObjects = (List<BasicDBObject>) results.getRawResults().get("results");
    BasicDBObject xObject = xObjects.get(0);

BigDecimal statResutl =

            new BigDecimal(Double.parseDouble(xObject.get("value").toString())).divide(new BigDecimal(10000));
    return statResutl;

你可能感兴趣的:(mongodb spring-mongo mapreduce)