Documents
store-and-access-data
store-and-access-data
Type
External
Status
Published
Created
Mar 5, 2026
Updated
Mar 6, 2026
Updated by
Dosu Bot

How to store and access data from a Strapi plugin#

To store data with a Strapi plugin, use a plugin content-type. Plugin content-types work exactly like other content-types. Once the content-type is created, you can start interacting with the data.

Create a content-type for your plugin#

To create a content-type with the CLI generator, run the following command in a terminal within the server/src/ directory of your plugin:

yarn strapi generate content-type
npm run strapi generate content-type

The generator CLI is interactive and asks a few questions about the content-type and the attributes it will contain. Answer the first questions, then for the Where do you want to add this model? question, choose the Add model to existing plugin option and type the name of the related plugin when asked.

Generating a content-type plugin with the CLI The strapi generate content-type CLI generator is used to create a basic content-type for a plugin.

The CLI will generate some code required to use your plugin, which includes the following:

Ensure plugin content-types are imported#

The CLI generator might not have imported all the related content-type files for your plugin, so you might have to make the following adjustments after the strapi generate content-type CLI command has finished running:

  1. In the /server/index.js file, import the content-types:
'use strict';

const register = require('./register');
const bootstrap = require('./bootstrap');
const destroy = require('./destroy');
const config = require('./config');
const contentTypes = require('./content-types');
const controllers = require('./controllers');
const routes = require('./routes');
const middlewares = require('./middlewares');
const policies = require('./policies');
const services = require('./services');

module.exports = {
  register,
  bootstrap,
  destroy,
  config,
  controllers,
  routes,
  services,
  contentTypes,
  policies,
  middlewares,
};

  1. In the /server/content-types/index.js file, import the content-type folder:
'use strict';

module.exports = {
  // In the line below, replace my-plugin-content-type
  // with the actual name and folder path of your content type
  "my-plugin-content-type": require('./my-plugin-content-type'),
};
  1. Ensure that the /server/content-types/[your-content-type-name] folder contains not only the schema.json file generated by the CLI, but also an index.js file that exports the content-type with the following code:
'use strict';

const schema = require('./schema');

module.exports = {
  schema,
};

Interact with data from the plugin#

Once you have created a content-type for your plugin, you can create, read, update, and delete data.

To create, read, update, and delete data, you can use either the Document Service API or the Query Engine API. While it's recommended to use the Document Service API, especially if you need access to components or dynamic zones, the Query Engine API is useful if you need unrestricted access to the underlying database.

Use the plugin::your-plugin-slug.the-plugin-content-type-name syntax for content-type identifiers in Document Service and Query Engine API queries.

Example:

Here is how to find all the entries for the my-plugin-content-type collection type created for a plugin called my-plugin:

// Using the Document Service API
let data = await strapi.documents('plugin::my-plugin.my-plugin-content-type').findMany();

// Using the Query Engine API
let data = await strapi.db.query('plugin::my-plugin.my-plugin-content-type').findMany();