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.
Hey @gak4u , 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?
@paulpopus you are lifesaver!!
Yep you have complete access to the models like @paulpopus 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.
Is there any way to access the mongo connection NOT through a model (e.g. so you could run database level operations?)
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
Discord
online
Get help straight from the Payload team with an Enterprise License.