Model.aggregate in 2.0

default discord avatar
sasjumb
last week
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?

  • discord user avatar
    denolfe
    Payload Team
    last week

    Have a look at the 2.0 release notes. There is a section about the new way to access the raw model.



    Instead of being

    payload.collections[myCollectionSlug].Model

    , it is now on the adapter like this

    payload.db.collections[myCollectionSlug]

    https://github.com/payloadcms/payload/releases/tag/v2.0.0
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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