Filter out objects with array containing value #14565
Replies: 7 comments 1 reply
-
@Naismith would you be able to supply a reproduction so that we can immediately test things out and make some changes? Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hey @DSchau Here is a repo containing both a strapi application (bare bones, using SQLite) and a barebones gatsby project, I've added the gatsby-source-strapi package to connect to strapi. If you need to login to strapi the username is |
Beta Was this translation helpful? Give feedback.
-
I realized I had forgotten to commit the local db of strapi. It should now work. An additional note, I created an article without any tags. So when I am filtering on articles that do not have 'Featured'. I feel this is still a valid article to pull. |
Beta Was this translation helpful? Give feedback.
-
To do this in Mongo, you'd use the following search filter (see here for more info):
Gatsby's GraphQL API uses sift to mimic Mongo filtering, but currently it appears that @DSchau does that sound right? Any other ideas? I haven't looked into Gatsby's GQL internals to know how difficult it would be to enable an additional key for filtering. EDIT: Here's a PoC on CodeSandbox - https://codesandbox.io/s/sift-poc-upm51 This would translate to the following query in GraphQL:
Relevant Docs |
Beta Was this translation helpful? Give feedback.
-
/cc @stefanprobst |
Beta Was this translation helpful? Give feedback.
-
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
Beta Was this translation helpful? Give feedback.
-
Summary
When writing a graphql query, I want to be able to search for Articles, and remove any results where tags contains a tag with a value. For example, excluding all Articles, that contains a tag of value 'Featured' in the tags array.
I have attempted to use the elemMatch, but this does not appear to solve my issue.
Relevant information
Example Article:
{ title: 'Example', tags: [ { tag: 'Featured' }, { tag: 'Blog' }, { tag: 'Custom' }, ] }
Environment (if relevant)
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.14.2 - ~/.nvm/versions/node/v10.14.2/bin/node
Yarn: 1.5.1 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.14.2/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Chrome: 74.0.3729.169
Firefox: 67.0
Safari: 12.1
npmPackages:
gatsby: ^2.5.0 => 2.5.0
gatsby-image: ^2.0.41 => 2.0.41
gatsby-plugin-extract-schema: 0.0.5 => 0.0.5
gatsby-plugin-manifest: ^2.1.1 => 2.1.1
gatsby-plugin-material-ui: ^2.0.1 => 2.0.1
gatsby-plugin-offline: ^2.1.0 => 2.1.0
gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12
gatsby-plugin-sharp: ^2.0.37 => 2.0.37
gatsby-remark-component: ^1.1.3 => 1.1.3
gatsby-source-filesystem: ^2.0.35 => 2.0.35
gatsby-source-strapi: 0.0.8 => 0.0.8
gatsby-transformer-remark: ^2.3.12 => 2.3.12
gatsby-transformer-sharp: ^2.1.19 => 2.1.19
npmGlobalPackages:
gatsby-cli: 2.6.2
File contents (if changed)
gatsby-config.js
: N/Apackage.json
: N/Agatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/ABeta Was this translation helpful? Give feedback.
All reactions