79553803

Date: 2025-04-03 19:21:25
Score: 1
Natty:
Report link

per @cmgchess -

This can all be done in two steps:

{
  _id: 1,
  categories: [123, 234],
  // other fields
}
{
  "_id": 1,
  "categories": [
    {
      "_id": 123,
      "value": "Category name"
    },
    {
      "_id": 234,
      "value": "Other category name"
    }
  ],
  // other fields
}
// operation:
{
  $set: {
    categories: {
      $map: {
        input: "$categories",
        as: "category",
        in: "$$category.value"
      }
    }
  }
}
// result:
{
  "_id": 1,
  "categories": [
    "Category name",
    "Other category name"
  ],
  // other fields
}

paydirt. :)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @cmgchess
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: dinx