我应该如何通过$和运营商在strapi中过滤数据

发布于 2025-02-07 22:28:28 字数 437 浏览 0 评论 0原文

我想通过createatstatus_invitorstatus_invited过滤我的表数据。我写这样的查询

const query = qs.stringify({
  filters: {
    $and: {
      createdAt: { $gte: firstDayOfTheMonth },
      createdAt: { $lt: lastDayOfTheMonth },
    },
    $and: {
      status_invitor: statusFilter
    },
    status_invited: statusFilter,
  },
});

,但无法正常工作

I want to filter my table data by createdAt,status_invitor and status_invited. I write query Like this

const query = qs.stringify({
  filters: {
    $and: {
      createdAt: { $gte: firstDayOfTheMonth },
      createdAt: { $lt: lastDayOfTheMonth },
    },
    $and: {
      status_invitor: statusFilter
    },
    status_invited: statusFilter,
  },
});

but is not working correctly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨敛清荷 2025-02-14 22:28:28

默认情况下将过滤器组合在一起,因此除非我误解了您要实现的目标,否则您无需使用$和操作员。

const query = qs.stringify({
  filters: {
    createdAt: { $gte: firstDayOfTheMonth },
    createdAt: { $lt: lastDayOfTheMonth },
    status_invitor: statusFilter,
    status_invited: statusFilter,
  },
});

如果您确实想混合和或过滤器,则需要指定一个数组。您可以在此处看到其中的示例: https://docs.strapi.io/developer-docs/latest/developer-resources/database-pabase-pabase-epis-reference/rest/filtering/filtering/filtering-localeing-locale--locale-publication一下/a>

The filters are combined by default so unless I have misunderstood what you are trying to achieve, you don't need to use the $and operator.

const query = qs.stringify({
  filters: {
    createdAt: { $gte: firstDayOfTheMonth },
    createdAt: { $lt: lastDayOfTheMonth },
    status_invitor: statusFilter,
    status_invited: statusFilter,
  },
});

If you do want to mix AND and OR filters then you need to specify an array. You can see examples of that here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#complex-filtering

烟雨凡馨 2025-02-14 22:28:28

我正在从事一个项目,我想用一个以上的搜索字段查询一个以上的字段。这是我用来使其工作的代码。我认为您需要做的就是更改$或为$,并且应该可以使用。

    const query = qs.stringify( {
    filters: {
        $or: [
            { name: { $contains: term }},
            { venue: { $contains: term } },
            { performers: { $contains: term } },
            { description: { $contains: term } },
        ],
    },
},
)

I'm working on a project where I wanted to query more than one field with a search term. This is the code I used to get it working. I think all you need to do is change the $or for the $and and it should work.

    const query = qs.stringify( {
    filters: {
        $or: [
            { name: { $contains: term }},
            { venue: { $contains: term } },
            { performers: { $contains: term } },
            { description: { $contains: term } },
        ],
    },
},
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文