Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- // select max(datetime), sum(precipitation)
- // from rain where source._id = 5bb4f8cd37a346769874ecdf and precipitation >= 4
- // group by year, month, day
- // order by datetime desc
- /*
- {
- "_id": ..,
- "source": {
- "name": ...
- "_id": ...
- }
- }
- */
- {
- "$match": {
- "$and": [
- {
- "source._id": "5bb4f8cd37a346769874ecdf"
- },
- {
- "precipitation": {
- "$gt": "4"
- }
- }
- ]
- }
- },
- {
- "$group": {
- "_id": {
- "year": {
- "$year": "$datetime"
- },
- "month": {
- "$month": "$datetime"
- },
- "day": {
- "$dayOfMonth": "$datetime"
- },
- "source\u1390_id": "$source._id",
- "source\u1390name": "$source.name"
- },
- "datetime": {
- "$max": "$datetime"
- },
- "precipitation": {
- "$sum": "$precipitation"
- }
- }
- },
- {
- "$project": {
- "_id": "1",
- "source.name": "$_id.source\u1390name",
- "source._id": "$_id.source\u1390_id",
- "datetime": "1",
- "location": "1",
- "precipitation": "1"
- }
- },
- {
- "$sort": {
- "datetime": "-1"
- }
- },
- {
- "$limit": "1"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement