How to concat results from 2 lookup operations within 1 aggregation pipeline?

I’m trying to concat the arrays that are the results of 2 lookup operations within a single aggregation pipeline. The results of both lookups are working fine, but the concat of them is resulting null and I cannot figure out why. Could be that Mongo wont acknowledge the lookup results as an array? But that doesnt make sense since I have access to it within the same project stage as arrays…So I dont know really…

The project stage from the pipeline:

{
    $project: {
      _id: 0,
      visitsTime: 1,
      bracketsTime: 1,
      chartResult: {
        $concatArrays: [
          "$visitsTime",
          "$bracketsTIme"
        ]
      }
    }
  }

The current results:

[
  {
    "bracketsTime": [
      {
        "date": "04-08-2022",
        "entryHours": 4.25
      },
      {
        "date": "04-10-2022",
        "entryHours": 6.5
      }
    ],
    "chartResult": null,
    "visitsTime": [
      {
        "date": "04-20-2022",
        "visitHours": 1
      },
      {
        "date": "04-10-2022",
        "visitHours": 3
      },
      {
        "date": "04-08-2022",
        "visitHours": 2
      },
      {
        "date": "05-26-2022",
        "visitHours": 2
      }
    ]
  }
]

Here is a link for a mongo playground I’ve been using for this pipeline:

Any suggestions would be greatly appreciated! thanks

Hi,

You have a typo. You typed bracketsTIme instead of bracketsTime.

When you update that, you example is working.

2 Likes

Much appreciated! I’m used to chasing down typos and syntax errors, but for some reason these aggregation pipelines make my eyes cross… Thank you

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.