-
Notifications
You must be signed in to change notification settings - Fork 25
$in operator doesn't work correctly through rest #88
Comments
What library are you using and what is the query string that gets passed? |
I'm not sure what you mean by library. I use the standard Feathers client. The query string is
|
I meant what REST client. |
Well, I use |
Also, try setting const qs = require('qs');
qs.parse('subfile=581b5574cde74e349157c5f2&number[$in][0]=98&number[$in][1]=99&number[$in][2]=100&number[$in][3]=101&number[$in][4]=102&number[$in][5]=103&number[$in][6]=104&number[$in][7]=105&number[$in][8]=106'); I get { subfile: '581b5574cde74e349157c5f2',
number: { '$in': [ '98', '99', '100', '101', '102', '103', '104', '105', '106' ] } } |
Oh, I understand now. I use regular I tried to set the |
I just checked, the same happens when I use jQuery. Though |
Yeah, I don't think it's the client. Pretty weird though because Express claims that it is using const url = require('url');
const qs = require('qs');
app.use(function(req, res, next) {
const query = url.parse(req.url).query;
req.query = qs.parse(query);
next();
}); And see if that does it. |
I just added tests for this in #90 and can't reproduce the problem. It looks like at least on the test server it is coming through fine. Maybe it is some other configuration issue? |
Okay, I just made a query manually and got a correct result ( |
I added tests for it for all REST clients in #90 (see e.g. https://github.com/feathersjs/feathers-rest/blob/master/test/client/fetch.test.js#L47) and they all pass. Can you share a setup that reproduces your problem? |
I spent like an hour to figure out what's the problem here, and it seems super weird. So, just try to pass the following array:
That's how I reproduced it: the The weirdest part is that only the length of that array matters. If you add another fields to the query, it doesn't change anything. |
That did sound strange but there seems to be an explanation for it in the qs documentation on array limiting.
Looks like the solution is to implement your own query parser using |
Thanks, that explains everything. The solution is simple, you just need to set the app.set('query parser', str => qs.parse(str, {arrayLimit: 1000})) It would be nice if you added it into the core, it may save a lot of hours of debugging for some people. |
This is more of a problem with Express's default settings and we usually try to not change those. It would be great if you could add it in the |
I post it here since exactly the same code works fine with
feathers-socketio
.So when I use the
$in
operator and provide an array of values for a field, the result query consists of an object, not an array. For example, the following queryresults in the following
hook.params.query
value:or see the debug console output:
This obviously doesn't pass as a correct query (in my case for Mongoose). As I mentioned, I see no such problem using socketio.
The text was updated successfully, but these errors were encountered: