"errmsg" : "Expression $trunc takes exactly 1 arguments. 2 were passed in.",

I’m getting this error message while trying to solve $unwind lab:

"errmsg" : "Expression $trunc takes exactly 1 arguments. 2 were passed in."

How are you going to truncate a value to a certain position given by a integer if you just pass one argument?

@JavierBlanco the syntax you’re using is only supported in >=4.2. From the documentation:

What this means is, in older versions, you would have to do some old school Maths to get the desired “truncation to a specific number of decimal places” effect, otherwise, it will truncate to a whole number.

Old school Maths —> truncate 123.456789 to 3 d.p.:

// Shift decimal point by 3 places to the right
123.456789 * 1000

// Truncate to a whole number
$trunc: 123456.789

// Shift decimal point by 3 places to the left
123456 / 1000

// Result is the number truncated to 3 d.p.
Result = 123.456

NB: You can perform steps 1 and 2 inside the $trunc function… as per the screenshot, it can accept expressions.

1 Like