cs-icon.svg

Query-based Export

Note: The Query-based Export plugin is currently in Beta phase.

The Contentstack CLI Query Export Plugin gives you full control to export only what you need, specific content types and their dependencies using queries.

The Query-based Export plugin lets you perform the following operations in Contentstack CLI:

  • Migrating specific content types.
  • Backing up filtered content.
  • Managing environments efficiently.

Key Features

Prerequisites

Installation

Run the following command to install the plugin:

csdx plugins:install @contentstack/cli-cm-export-query

To verify the installation, run:

csdx plugins

Usage

csdx cm:stacks:export-query [OPTIONS]

Options

  • -k, --stack-api-key=stack-api-key: API key of the source stack.
  • --query=query: Query string or file path. Refer to the Query Format section.
  • -d, --data-dir=data-dir: Absolute path to the folder to store the exported content.
  • -a, --alias=alias: Management token alias of the source stack.
  • --branch=branch: [default: main] Name of the branch where you want to export content.
  • -c, --config=config: Path to the configuration JSON file containing all the options for a single run.
  • --skip-references: Skip referenced content types.
  • --skip-dependencies: Skip global fields, extensions, and taxonomies.
  • --secured-assets: [optional] Use this flag to export your content if the secured assets feature is enabled for your stack.

Query Format

Use the following query structure to filter content types. Replace placeholders with appropriate field names and values.

{
  "modules": {
    "content-types": {
      "<field>": {
        "<operator>": "<value>"
      }
    }
  }
}

Example Operators: $in,$regex,$gte.

Additional Resource: Refer to the Content Delivery API Queries for the full list of operators.

Examples

  • To export content types by title:
    csdx cm:stacks:export-query -a prod-alias --query '{"modules":{"content-types":{"title":{"$in":["Blog","Author"]}}}}'
  • To export using a query from a file:
    csdx cm:stacks:export-query -a prod-alias --query ./my-query.json

    my-query.json:

    {
      "modules": {
        "content-types": {
          "$and": [
            { "uid": { "$in": ["author","blog_post"] }}
          ]
        }
      }
    }

Supported Modules

  • Query-supported Module
    • content-types: Schema and configuration of content types.
  • Automatically Exported Dependencies
    • global-fields: Linked global fields.
    • extensions: Standard and marketplace custom field extensions.
    • marketplace-apps: Marketplace integrations.
    • taxonomies: Referenced taxonomy definitions.
  • Always Exported Modules
    • stack: Stack metadata.
    • locales: Language settings.
    • environments: Deployment environments.
    • personalize: Personalize project.
  • Content Data Modules
    • entries: Entries of all exported content types.
    • assets: All assets linked in exported entries.

Limitations

  • Only content type queries are supported.
  • All asset folders are exported. Folder-level filtering is not supported.
Was this article helpful?
^