hi,
i want to write a query where i can get a number of records from the student table group by year.

in sql
select count(*) from student group by year

tell me how to write it in mongodb redash

Thanks

1 Like

here is the solution -:

{
"collection": "student",
"aggregate": [{
	"$unwind": "$YEAR"
},
{
	"$group": {
		"_id": "$YEAR",
		"count": {
			"$sum": 1
		}
	}
}]
	
}
1 Like

Thanks for posting your solution!