如何获得spring-data-mongodb的趋势?

时间:2016-05-17 13:18:27

标签: java mongodb spring-data-mongodb

参考此链接MongoDB : Is there a way to detect a value trend using aggregation?我们正在使用spring-data-mongodb,我们想要计算趋势和总销售额。我们提出了两个问题来获取趋势和总销售额,是否有任何有效的方法来做同样的事情?请帮忙。

示例数据:

 {"2000-01-01", 1000, "$"}
 {"2000-01-01", 1000, "$"}
 {"2000-01-01", 1000, "$"}
 {"2001-02-01", 2000, "$"}
 {"2001-02-01", 2000, "$"}
 {"2001-02-01", 2000, "$"}
 {"2002-03-01", 3000, "$"}
 {"2002-03-01", 3000, "$"}
 {"2002-03-01", 3000, "$"}
 {"2003-04-01", 4000, "$"}  
 {"2003-04-01", 4000, "$"} 
 {"2003-04-01", 4000, "$"}

例如,我们计算期间的总销售额" 2003-01-01" (开始日期)到" 2004-01-01" (结束日期)在查询中,结果为:$ 12000。 我们通过另一个查询计算的趋势" 2002-01-01" (开始日期)到" 2003-01-01" (上一个查询的开始日期),

    and the result comes out to be : $9000 , 

  subtract the previous result $12000 - $9000 (current result) = $3000 trends.

是否有可能编写一个有效的单一有效查询来计算总销售额和spring-data-mongodb的总体趋势? 我们尝试了以下方法:

   ** by concurrently running the two tasks (one of calculation gross sales and other of calculating trends) by threads and it seems forking thread from the java web application can be disastrous

 ** by using map reduce program in spring-data-mongodb, but of NO use, because we were unable to get the query for pre-dated date to run using map reduce.

请帮助我了解其他更好的选择,尝试使用spring-data-mongodb同时执行计算趋势和总销售额。 问候 克里斯

0 个答案:

没有答案