Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

let allSkills = await strapi.entityService.findMany(‘api::skill.skill’, { filters: {…

  1. User

    let allSkills = await strapi.entityService.findMany(‘api::skill.skill’, { filters: { $not: { is_blokced: 1, }, }, }); 多个过滤条件。 const card_class = ctx.request.query.card_class; const health = ctx.request.query.health; const attack = ctx.request.query.attack; const cost = ctx.request.query.cost; 这几个参数 同时相同 的过滤条件应该怎么写

  2. Assistant

    可以使用 $and 运算符将多个相同的过滤条件组合起来。下面是一个示例:

    const allSkills = await strapi.entityService.findMany('api::skill.skill', {
      filters: {
        $and: [
          { card_class: card_class },
          { health: health },
          { attack: attack },
          { cost: cost },
        ],
        $not: {
          is_blocked: 1,
        },
      },
    });
    

    在上述示例中,通过使用 $and 运算符将 card_class、health、attack 和 cost 参数的相同过滤条件组合在一起,并且添加了排除 is_blocked: 1 的条件。请注意,这里使用了正确的属性名称,并且使用了下划线 _ 代替了 is_blokced。

    最后,可以使用上述代码来过滤具有相同条件的记录。

  3. User

    重新回答下

  4. Assistant

    如果要同时将多个参数作为相同过滤条件进行查询,可以使用逻辑运算符 $and 将它们组合在一起。以下是一个示例:

    const card_class = ctx.request.query.card_class;
    const health = ctx.request.query.health;
    const attack = ctx.request.query.attack;
    const cost = ctx.request.query.cost;
    
    const allSkills = await strapi.entityService.findMany('api::skill.skill', {
      filters: {
        $and: [
          { card_class: card_class },
          { health: health },
          { attack: attack },
          { cost: cost }
        ],
        is_blocked: { $ne: 1 }
      }
    });
    

    在上面的示例中,使用逻辑运算符 $and 将参数 card_class、health、attack 和 cost 的过滤条件组合在一起,同时使用 $ne 运算符将 is_blocked 的值排除为 1。

    请注意,以上代码假设参数已经正确传递,并且通过检查参数的有效性和存在性来避免潜在的错误。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.