I'd like to know how to implement a Standard Deviation aggregation Function to use in Spring Mongo Data.
I Know Mongo DB 3.2 has a Standard Deviation aggregation function, but It isn't available in Spring Data.
Could I use the Mongo's aggregation function?
Thanks.
There is a distinct difference between "not available" and "no implemented helper method", and that is the real case here. Just because there is no "helper" for implementing the
$stdDevSamp
or$stdDevPop
operators, does not mean they cannot be used, as long as you are connecting to a MongoDB 3.2 instance of course.All you really need is a custom class supporting the
AggregationOperation
interface, that will allow construction usingDBObject
:Then you can use that class in aggregation pipeline construction like so:
And that is the equivalent of the documentation example:
As an interface for
AggregationOperation
the class easily mixes with the implemented helpers:So you can still use features even if there is no "buit in helper" to work out the BSON Object construction for you. You just do the construction yourself.