Search code examples
strapi

What db methods are available in Strapi v3 by default?


https://strapi.io/blog/using-database-transactions-to-write-queries-in-strapi?utm_source=dev.to&utm_medium=post&utm_id=blog

I read the documentation for v3, but it doesn't tell me what mongoose methods I have access to from the beginning, so I was wondering if there were any guide or documentation that told me how to access all the Mongoose methods for article for example?

I tried calling

strapi.services.article.findMany({
    offset: 10,
    limit: 10,
    where: {
        id: ctx.query.id
    }
})

But I got: strapi.services.article.findMany is not a function

It works if I do:

strapi.services.article.find(ctx.query)

Solution

  • Strapi provides a query API to interact with the database layer. Whether you're using mysql, postgres or mongodb, the API will have the same interface by definition (see query API documentation).

    find is the way to go to find many entries.

    PS: Since the article you posted is about database transaction with Strapi, I advise you to read my article about the caveats to be aware of.