Search code examples
arraysnode.jswhere-clauseloopbackjsstrongloop

Strongloop Loopback: where filter with two arrays


I want to add a where filter in strongloop / loopback which compares two different arrays.

I have the following model:

"properties": {
  ...
  "audience": {
    "type": [
      "string"
    ],
  ...  
}

I want to create a where clause which returns all items where at least one element from 'audience' matches at least one element of another array.

Examples with "audience": ["A", "B", "C"]

  • "anotherArray": ["A", "Z"] => should match!
  • "anotherArray": ["A", "B"] => should match!
  • "anotherArray": ["B"] => should match!
  • "anotherArray": ["Z", "Y"] => should not match!
  • "anotherArray": ["Z"] => should not match!

The filter {where: { audience: { inq: anotherArray}}}; does not seem to do the trick...


Solution

  • This doesn't work if the string values are ids. See comment of Ebrahim Pasbani above.