{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/2824","repository_url":"https://api.github.com/repos/strongloop/loopback","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/2824/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/2824/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/2824/events","html_url":"https://github.com/strongloop/loopback/issues/2824","id":181184332,"number":2824,"title":"Error when having many filter in `filter[where][or][0][id]=1` format","user":{"login":"davidcheung","id":1787590,"avatar_url":"https://avatars.githubusercontent.com/u/1787590?v=3","gravatar_id":"","url":"https://api.github.com/users/davidcheung","html_url":"https://github.com/davidcheung","followers_url":"https://api.github.com/users/davidcheung/followers","following_url":"https://api.github.com/users/davidcheung/following{/other_user}","gists_url":"https://api.github.com/users/davidcheung/gists{/gist_id}","starred_url":"https://api.github.com/users/davidcheung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidcheung/subscriptions","organizations_url":"https://api.github.com/users/davidcheung/orgs","repos_url":"https://api.github.com/users/davidcheung/repos","events_url":"https://api.github.com/users/davidcheung/events{/privacy}","received_events_url":"https://api.github.com/users/davidcheung/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/doc","name":"doc","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-05T15:15:52Z","updated_at":"2016-10-05T19:39:20Z","closed_at":null,"body":"### Problem \r\nwhen a user sends a GET request with many filters with this format as follows\r\n```coffeescript\r\nhttp://localhost:3000/api/Books?\r\nfilter[where][or][0][id]=1\r\n&filter[where][or][1][id]=2\r\n&filter[where][or][2][id]=1\r\n&filter[where][or][3][id]=1\r\n&filter[where][or][4][id]=1\r\n&filter[where][or][5][id]=1\r\n&filter[where][or][6][id]=1\r\n&filter[where][or][7][id]=1\r\n&filter[where][or][8][id]=1\r\n&filter[where][or][9][id]=1\r\n&filter[where][or][10][id]=1\r\n&filter[where][or][11][id]=1\r\n&filter[where][or][12][id]=1\r\n&filter[where][or][13][id]=1\r\n&filter[where][or][14][id]=1\r\n&filter[where][or][15][id]=1\r\n&filter[where][or][16][id]=1\r\n&filter[where][or][17][id]=1\r\n&filter[where][or][18][id]=1\r\n&filter[where][or][19][id]=1\r\n&filter[where][or][20][id]=1\r\n&filter[where][or][21][id]=1\r\n```\r\n\r\nwhen the Array `or[]` have over 20 indices it maps it as an object\r\nresulting in [juggler throwing an error](https://github.com/strongloop/loopback-datasource-juggler/blob/99a864e9c6ef4907ed32425ef1f196d2677d17a8/lib/dao.js#L1551)\r\n\r\nthis behavior is caused by express query parser https://github.com/ljharb/qs#parsing-arrays where default `arrayLimit` is 20\r\nso `req.query.where.filter.or` becomes an object once it hits 20 indices \r\n\r\n### How to adjust the limit\r\ninclude `qs` in your `server/server.js` and override the query parser function\r\n```js\r\n'use strict';\r\n\r\nvar loopback = require('loopback');\r\nvar boot = require('loopback-boot');\r\nvar qs = require('qs');\r\n\r\nvar app = module.exports = loopback();\r\napp.set('query parser', function(value, option) {\r\n  return qs.parse(value, {arrayLimit: 500});\r\n});\r\n\r\napp.start = function() {\r\n```\r\n\r\n### Solution \r\nI dont think it make sense to just increase the number, since there is no \"correct\" number to set it as, while it is unclear to users that this would be a problem, perhaps all we can do is document this behavior?\r\n\r\n@strongloop/loopback-dev @b-admike thoughts?"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/251777044","html_url":"https://github.com/strongloop/loopback/issues/2824#issuecomment-251777044","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/2824","id":251777044,"user":{"login":"superkhau","id":1617364,"avatar_url":"https://avatars.githubusercontent.com/u/1617364?v=3","gravatar_id":"","url":"https://api.github.com/users/superkhau","html_url":"https://github.com/superkhau","followers_url":"https://api.github.com/users/superkhau/followers","following_url":"https://api.github.com/users/superkhau/following{/other_user}","gists_url":"https://api.github.com/users/superkhau/gists{/gist_id}","starred_url":"https://api.github.com/users/superkhau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superkhau/subscriptions","organizations_url":"https://api.github.com/users/superkhau/orgs","repos_url":"https://api.github.com/users/superkhau/repos","events_url":"https://api.github.com/users/superkhau/events{/privacy}","received_events_url":"https://api.github.com/users/superkhau/received_events","type":"User","site_admin":false},"created_at":"2016-10-05T19:39:20Z","updated_at":"2016-10-05T19:39:20Z","body":"There is nothing to resolve here as this is expected behaviour in express/qs. We should document the workaround for end-users though. I see this as a doc issue and not a bug, gonna relabel. @crandmck Can you help document this?"}}
{"actor":{"display_login":"superkhau"}}