database - 如何删除“Strapi”中具有特定值的条目?
问题描述
在 headless-cms Strapi 中的某些情况下删除条目的正确方法是什么?如果一种内容类型获得特定值。
例如,如果日期已到/已过期。就我而言,我创建了一个活动日历。它有一些内容类型,如标题、位置和日期。到达事件日期后,每个事件都必须自动消失。我怎样才能做到这一点?
解决方案
我建议你使用 CRON 任务。此功能在 Strapi 中可用
这是文档https://strapi.io/documentation/3.0.0-beta.x/configurations/configurations.html#cron-tasks。
因此,按照文档创建您的 CRON 任务,然后在函数中,您必须获取日期低于 CRON 函数执行日期的数据。
为此,您可以使用查询功能。
// Fetch data that have the `yourDateAttributeName_lt` lower than the now.
const data = await strapi.query('article').find({
yourDateAttributeName_lt: new Date()
});
// Delete all entries fetched.
data.forEach((entry) => strapi.query('article').delete({
id: entry.id
}));
推荐阅读
- android - 如何在 Firebase 实时数据库中上传带有附加数据的图像?
- coq - 坚持使用列表归纳的 Coq 证明
- python-3.x - Python - 基于不同的列转置/旋转列
- sql-server - 多个索引或覆盖索引和包含?
- flutter - Flutter 中 ListView.builder 上的 GestureDetector
- jolt - 将一个数组移动到另一个数组中定义的 json 对象中 - JOLT 转换
- python - 如何从python中的列表中删除类型字符串元素?
- c++ - 通过 C++ HDF5 API 读取 H5T_STRING 数据类型
- tensorflow - Tensorflow 1.15 + CUDA + cuDNN 安装使用 Conda
- amazon-web-services - AWS EB(Elastic Beanstalk)CLI 在 git bash 的命令行中不起作用