The $trunc accumulator is a unary operator

Hi, can someone help me understand why below query is causing - “errmsg” : “The $trunc accumulator is a unary operator”

$match: {
“imdb.rating”: { $exists: true, $ne: null, $ne: “” },
awards: {$exists: true, $ne: null}
$group: {
_id: 0,
“stdDevSampleRating”: {$trunc: [{$stdDevSamp: “$imdb.rating”}, 4]}


Hi @Shravan,

You can refer to the following documentation link:

Please feel free to reach out if you still have any questions.

Kind Regards,

Thanks for your reply @Sonali_Mamgain. I did go through documentation referenced earlier and there isn’t such an example or any reference to $trunc being a unary operator or what is not allowed. Per documentation, first argument to $trunc ''Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long." and I am sure ‘{$stdDevSamp: “$imdb.rating”}’ expression resolves to an a number. So, am not sure what that error is trying to say. Does above expression resolves to a document rather a number like: {10} instead of 10?

I am also getting the same error . Did you find the solution ? If so please post

Please check this link.It may help
Certain operators not allowed in group stage

Trouble using $trunc inside of $group

Thanks @Ramachandra_37567. I got that fixed . Splitter that to different stages.

hi @swapna_sudhanthiran,

This wikipedia article clarified me on unary operator and issue in this post - Unary operation - Wikipedia.

As mentioned and referenced by @Ramachandra_37567, $group does not allow unary operators like: $subtract and $trunc and hence the error.

Thanks @Shravan