MongoDB Aggregation Framework doesn't have floor
function.
It only has simple arithmetic operators.
So, how to compose floor
function using them?
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How to represent an array with mixed types
According to definition
floor(number) = number - (number % step)
we can compose our aggregation formula:where
step
is order of magnitude. First, it computes remainder with$mod
and then it computes difference with$subtract
.So, grouping Users by
age
floored to whole numbers will beIf you want to floor to 10s or 1000s use 10 or 1000 instead of 1.