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

Query $in with more than 21 items throw a MongooseError.CastError #205

Closed
loicbisiere opened this Issue Jul 27, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@loicbisiere

loicbisiere commented Jul 27, 2017

Steps to reproduce

var query = {
          cId: {
            $in: _.fill(Array(22), "test")
          }
        };

app.service("my-service").find({query:query})

Generate this error:

CastError: Cast to string failed for value "{ '0': 'test',
  '1': 'test',
  '2': 'test',
  '3': 'test',
  '4': 'test',
  '5': 'test',
  '6': 'test',
  '7': 'test',
  '8': 'test',
  '9': 'test',
  '10': 'test',
  '11': 'test',
  '12': 'test',
  '13': 'test',
  '14': 'test',
  '15': 'test',
  '16': 'test',
  '17': 'test',
  '18': 'test',
  '19': 'test',
  '20': 'test',
  '21': 'test' }" at path "cId" for model "profiles"
    at MongooseError.CastError (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/error/cast.js:26:11)
    at SchemaString.cast (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/schema/string.js:455:9)
    at SchemaString.castForQuery (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/schema/string.js:509:15)
    at SchemaString.handleArray (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/schematype.js:908:18)
    at SchemaString.castForQuery (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/schema/string.js:503:20)
    at cast (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/cast.js:217:39)
    at Query.cast (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/query.js:2915:12)
    at Query.find (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/query.js:1168:10)
    at /Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/query.js:2728:21
From previous event:
    at Query.exec (/Users/loicbisiere/projects/2PS/api/node_modules/mongoose/lib/query.js:2722:17)
    at executeQuery (/Users/loicbisiere/projects/2PS/api/node_modules/feathers-mongoose/lib/service.js:134:18)
    at Object._find (/Users/loicbisiere/projects/2PS/api/node_modules/feathers-mongoose/lib/service.js:159:14)
    at Object.find (/Users/loicbisiere/projects/2PS/api/node_modules/feathers-mongoose/lib/service.js:165:25)
    at /Users/loicbisiere/projects/2PS/api/node_modules/feathers-hooks/lib/hooks.js:101:31
    at new Promise (/Users/loicbisiere/projects/2PS/api/node_modules/core-js/modules/es6.promise.js:191:7)
    at /Users/loicbisiere/projects/2PS/api/node_modules/feathers-hooks/lib/hooks.js:85:16
    at run (/Users/loicbisiere/projects/2PS/api/node_modules/core-js/modules/es6.promise.js:87:22)
    at /Users/loicbisiere/projects/2PS/api/node_modules/core-js/modules/es6.promise.js:100:28
    at flush (/Users/loicbisiere/projects/2PS/api/node_modules/core-js/modules/_microtask.js:18:9)
    at _combinedTickCallback (node.js:376:9)
    at process._tickCallback (node.js:407:11)

If $in array length > 21 crash, if $in array length <= 21 no problem.

System configuration

Module versions

  • feathers 2.1.1
  • feathers-mongoose 5.0.3
  • mongoose 4.9.2

NodeJS version:
v5.9.1

Operating System:
MaxOSX 10.11.6

@daffl

This comment has been minimized.

Member

daffl commented Jul 27, 2017

You are most likely using the REST client in which case this is a duplicate of feathersjs-ecosystem/feathers-rest#88.

The issue is a limitation in the querystring module which limits the size of arrays to 20 items. The recommended solution is to implement your own query parser with the arrayLimit option set to a higher value.

@daffl daffl closed this Jul 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment