What is the MongoDB equivalent for the following SQL query?
SELECT
station_id,
group_concat('signals')
FROM signals
GROUP BY station_id
i need to group by "station id", and concat "signal", thanks, the result would be like that:
| station_id | signals |
321 2,3,5,2
Please refer following aggregate query as an equivalent query of SQL into Mongodb
db.signals.aggregate(
// Pipeline
[
// Stage 1
{
$group: {
_id: '$station_id',
signals: {
$push: '$signal'
}
}
},
]
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.