【问题标题】:Strapi how query relationship in CRONStrapi 如何在 CRON 中查询关系
【发布时间】:2020-08-02 10:31:21
【问题描述】:

我正在尝试在strapi中编写一个CRON来查询post_status的产品:“草稿”并且用户名被阻止是错误的。如果为真,则不应显示和结果。 用户名与产品具有一对多关系。

"use strict";


module.exports = {
  "*/1 * * * *": async () => {
    const draftProductToPublishToFacebook = await strapi.api.product.services.product.find(
      {
        post_status: "Draft",
        published_at_lt: new Date(),
        username: {
          blocked: false,
        },
      }
    );
  },
};

样本数据

{
    post_status: 'Draft',
    _id: 5eef02af7761f1425dd0ccec,
    stock_status: 'test',
    product_status: 'publish',
    __v: 0,
    username: {
      confirmed: true,
      blocked: false,
      _id: 5eef05985f864742725ab8e1,
      username: 'test2',
      email: 'test2@test.com',
      provider: 'local',
      createdAt: 2020-06-21T07:00:40.996Z,
      updatedAt: 2020-07-17T01:24:58.918Z,
      __v: 0,
      role: 5ee30d5424f89d5253877e90,
      id: '5eef05985f864742725ab8e1'
    },
    published_at: 2020-08-02T00:20:00.000Z,
    id: '5eef02af7761f1425dd0ccec'
  }

我遇到的错误 (node:3652) UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "{blocked: false }" at path "username" for model "product"

谢谢

【问题讨论】:

    标签: strapi


    【解决方案1】:
    'username.blocked': false
    

    应该可以。

    【讨论】:

      猜你喜欢
      • 2019-11-26
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      相关资源
      最近更新 更多