Is there a floor function in Mongodb aggregation framework?

有些话、适合烂在心里 提交于 2019-12-18 08:14:18

问题


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?


回答1:


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.




回答2:


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> }



来源:https://stackoverflow.com/questions/13617526/is-there-a-floor-function-in-mongodb-aggregation-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!