0

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
9

1 Answer 1

1

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

    ]

);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.