Model.aggregate in 2.0

default discord avatar
sasjumb10 months ago
1

Hello you used to be able to aggregate to only get the props you need like so



`
 const payload = await getPayloadClient();

  const model = payload.collections[SolutionsPagesCms.slug].Model;
  const solutionsShort = await model.aggregate<{ id: string; slug: string }>([
    {
      $group: {
        _id: { $toString: "$_id" },
        slug: { $first: "$slug" }, // Using $first to get the slug of the first document in each group
      },
    },
  ]);

`



However I'm not sure how you would do that in 2.0 any ideas?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.