These are chat archives for Automattic/mongoose

24th
Sep 2017
Karthik Iyengar
@karthikiyengar
Sep 24 2017 14:45

Quick query - here’s a part of my aggregation pipeline:

{
  $lookup: {
    from: "users", localField: "userId", foreignField: "_id", as: "users”}
  },
  {
    $group: { 
      _id: “$someid",
      users: {$push: "$users.somevalue"}
  }
}

This returns an array of arrays for users - I guess I’m just missing the right keyword here. How can get a flattened list of users.somevalues?

Karthik Iyengar
@karthikiyengar
Sep 24 2017 14:53
In case anyone is interested, we need a $unwind after the lookup to do this.