Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Native mongodb queries within payload

default discord avatar
gak4u2 years ago
5

Can I write native mongodb queries within payload without creating new connection? I would like to do some aggregations and also do some count queries.

  • default discord avatar
    paulpopus2 years ago

    Hey

    @661298338939011077

    , I couldn't find the docs page for this but you have direct access to the mongoose model inside the local API via

    collections.slug.Model

    Does this fit within your needs?

  • default discord avatar
    gak4u2 years ago
    @858693520012476436

    you are lifesaver!!

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Yep you have complete access to the models like

    @858693520012476436

    described.



    When accessing a model directly just know that things like access-control & hooks will not run (which is fine). Only

    payload.

    operations (create/read/update/delete etc.) trigger hooks and access control to run.

  • default discord avatar
    ssyberg2 years ago

    Is there any way to access the mongo connection NOT through a model (e.g. so you could run database level operations?)

  • discord user avatar
    jmikrut
    2 years ago

    that's a question for mongoose honestly but it's a good question



    i bet mongoose has some way of doing that



    payload itself doesn't though

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.