Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Concat strings in nested json with other string in MongoDB

I am trying an aggregation in MongoDB in order to convert:

[
  {
    "_id": ObjectId("5a934e000102030405000000"),
    "acronym": "MC",
    "tickers": [
      {
        "name": "Sensor1-front",
        "symbol": "s1f"
      },
      {
        "name": "Sensor1-back",
        "symbol": "s1b"
      }
    ]
  }
]

into something like this:

['s1f.MC','s1b.MC']

Where each symbol in tickers is concat to acronym.

I am trying it with $concat, $group, etc but I am not going anywhere.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use reduce

db.collection.aggregate([
  {
    $addFields: {
      newField: {
        "$reduce": {
          "input": "$tickers",
          "initialValue": [],
          "in": {
            "$concatArrays": [
              [
                {
                  "$concat": [
                    "$$this.symbol",
                    ".",
                    "$acronym"
                  ]
                }
              ],
              "$$value"
            ]
          }
        }
      }
    }
  }
])

Working Mongo playground

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!