Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

$in: [] returning unexpected results #113

Closed
j2L4e opened this issue May 3, 2017 · 2 comments
Closed

$in: [] returning unexpected results #113

j2L4e opened this issue May 3, 2017 · 2 comments

Comments

@j2L4e
Copy link
Contributor

j2L4e commented May 3, 2017

This happens on the client with feathers-rest and axios:

.find({
  query: {
    foo: {
      $in: foos
    }
  }
});

With foos = [] this produces an HTTP request with an empty query string, i.e. a plain .find() and thus it returns all records.

I'd expect it to actually return an emtpy array.

As a workaround i use which returns the expected result (none) for an empty foos array.

.find({
  query: {
    foo: {
      $in: [...foos, '__dummy']
    }
  }
});
@daffl
Copy link
Member

daffl commented May 3, 2017

This is a limitation on how query strings work and not really anything we can change. As the qs documentation states:

Key with no values (such as an empty object or array) will return nothing:

assert.equal(qs.stringify({ a: [] }), '');
assert.equal(qs.stringify({ a: {} }), '');
assert.equal(qs.stringify({ a: [{}] }), '');
assert.equal(qs.stringify({ a: { b: []} }), '');
assert.equal(qs.stringify({ a: { b: {}} }), '');

@j2L4e
Copy link
Contributor Author

j2L4e commented May 4, 2017

I see, thanks for clarifying.

@j2L4e j2L4e closed this as completed May 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants