I try to do some integer math in mongodb and have some problems. Is there a way to round doubles up or down in the mongo db aggregation framework?
As per the comment from Stennie, the floor and ceiling methods are not supported.
And as per my comment above, the best solution that I could find was just doing an operation that looks like: (num-mod(num,1)) which should yield the same result as the floor function.
Starting from MongoDB 3.2, you can use the following arithmetic aggregation operators are available:
ceil
trunc
floor
which allow to convert to integer from any side you want. The syntax is straight-forward: { $function: <number> }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With