question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How do we query to filter based on 2+ array items on the front-end?

See original GitHub issue

Considering a simple use case where I have the following records of Books loaded into Vuex store of the Books Service. Each book contains a list of tags.

Book 1 Coding Javascript Education Book 2 Javascript Coding FeathersJS Book 3 Javascript FeathersVuex FeathersJS Coding

How do I query for books that have Coding & FeathersJS tags?

query: {
    tag: {
         $in: ['Coding', 'FeathersJS']
    }
}

This gives results for the books that have the Coding or FeathersJS tags as expected. (Book1, Book2, Book3)

I am not sure how to query for books that contain both the tags.

On the backend with mongoose, I can use the $all operator to achieve this - but how do I go about doing this on the frontend?

Currently, my workaround was to have a custom getter on the service which executes the $in query and then loops through the results to find the items where both tags are present.

Is there a better way to do this? Did I miss something w.r.t querying?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
marshallswaincommented, May 24, 2020

I would really appreciate a PR if this will benefit users. I’m a bit strapped for time for the next week or so, but I can review PRs and do releases. Thanks guys!

0reactions
marshallswaincommented, Sep 2, 2020

@kshitizshankar thanks for the details in your last comment. I was able to make the PR and have published it as feathers-vuex@3.12.1. Please reopen this issue if you still find that there’s a problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to filter the array by multiple values from another array
In my code I create a local temporary array elall that contains all of the keywords in an element from both attributes (...
Read more >
Filter, Sort, and Search Arrays with JavaScript - Server Side Up
Add some quick filtering, sorting, and searching to your arrays with JavaScript and VueJS for that extra level of user experience!
Read more >
How To Use the filter() Array Method in JavaScript | DigitalOcean
Use filter() on arrays to go through an array and return a new array with the elements that pass the filtering rules.
Read more >
How to Search and Filter Components in React - freeCodeCamp
For this tutorial we are going to be using one of Frontend ... How to Search for Items in the API; How to...
Read more >
Querying and Scanning a DynamoDB Table - AWS SDK for ...
query (params, function(err, data) { if (err) { console.log("Error", err); } else { //console.log("Success", data.Items); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found