Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching by [in array] #33

Open
jbotte opened this issue Feb 23, 2017 · 2 comments
Open

Searching by [in array] #33

jbotte opened this issue Feb 23, 2017 · 2 comments
Labels

Comments

@jbotte
Copy link

jbotte commented Feb 23, 2017

Storing geojson offline for a node application, looking to do queries such as...

Find all features that are in cat 4,

find all features in cat 4 or cat 8

things like that.

screen shot 2017-02-23 at 1 03 10 pm

@mmckegg
Copy link
Collaborator

mmckegg commented Apr 5, 2017

You can use the ~ to match items in an array. But unfortunately it will only work with strings:

var jsonQuery = require('../')
var data = {
  features: {
    0: {
      type: 'Feature',
      cats: ['4', '8']
    },
    1: {
      type: 'Feature',
      cats: ['8', '9']
    }
  }
}

var result = jsonQuery('features[**][*cats~4|cats~9]', {data})
console.log(result.value)

Although potentially you could pass the cats as params which would let you use numbers:

var jsonQuery = require('../')
var data = {
  features: {
    0: {
      type: 'Feature',
      cats: [4, 8]
    },
    1: {
      type: 'Feature',
      cats: [8, 9]
    }
  }
}

var result = jsonQuery(['features[**][*cats~?|cats~?]', 8, 9], {data})
console.log(result.value)

Otherwise you can always create a helper function.

@JayCole
Copy link

JayCole commented Apr 12, 2017

Can you add your examples to the documentation.
This answer helped me a lot.
Thanks.
Here's what I need to do.
get a list of jobs with Roll Forming.

var data = {
    "jobs": [{
        "id": "1234fsfs44234",
        "number": "126545",
        "name": "jones",
        "description": [ "install", "roll form" ],  
        "asignedto": ["bill", "jay"],			
    }, {
        "id": "1234f4",
        "number": "12345",
        "name": "smith",
        "description": [ "install", "roll form" ],  
        "asignedto": ["jay", "bill"],		
    }]
}

var result = jsonQuery('jobs[**][*description~roll form]', {data})
console.log(result.value)

I can see you've made a "OR"operator "|" is there also an "AND" operator "&"?
[*description~roll form & asignedto~jay] index aligned if description[1] = true & asingedto must also be in index[1] to be = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants