GET Bears using BearId is returning cast exception
gquintana16 opened this issue · 1 comments
Calling using http://localhost:8080/api/bears/723d7fef-fdcf-435c-9148-8329ac372c3f
StackTrace:
An error occurred while reading that Bear { CastError: Cast to ObjectId failed for value "723d7fef-fdcf-435c-9148-8329ac372c3f" at path "_id" for model "Bear"
at new CastError (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\error\cast.js:27:11)
at ObjectId.cast (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\schema\objectid.js:158:13)
at ObjectId.SchemaType._castForQuery (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\schematype.js:1064:15)
at ObjectId.castForQuery (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\schema\objectid.js:198:15)
at ObjectId.SchemaType.castForQueryWrapper (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\schematype.js:1021:15)
at cast (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\cast.js:269:32)
at model.Query.Query.cast (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\query.js:3142:12)
at model.Query.Query._castConditions (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\query.js:1146:10)
at model.Query.Query._findOne (C:\Users\ginoq\Documents\node-api-mattb\node_modules\mongoose\lib\query.js:1353:8)
at C:\Users\ginoq\Documents\node-api-mattb\node_modules\kareem\index.js:250:8
at C:\Users\ginoq\Documents\node-api-mattb\node_modules\kareem\index.js:23:7
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'Cast to ObjectId failed for value "723d7fef-fdcf-435c-9148-8329ac372c3f" at path "_id" for model "Bear"',
name: 'CastError',
stringValue: '"723d7fef-fdcf-435c-9148-8329ac372c3f"',
kind: 'ObjectId',
value: '723d7fef-fdcf-435c-9148-8329ac372c3f',
path: '_id',
reason: undefined,
model:
{ [Function: model]
hooks: Kareem { _pres: {}, _posts: {} },
base:
Mongoose {
connections: [Array],
models: [Object],
modelSchemas: [Object],
options: [Object],
plugins: [Array] },
modelName: 'Bear',
model: [Function: model],
db:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
hosts: null,
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
name: 'node-api',
options: [Object],
otherDbs: [],
states: [Object],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
_listening: false,
db: [Object],
_events: [Object],
_eventsCount: 1 },
discriminators: undefined,
'$appliedHooks': true,
_events: { init: [Function], save: [Function] },
_eventsCount: 2,
schema:
Schema {
obj: [Object],
paths: [Object],
aliases: {},
subpaths: {},
virtuals: [Object],
singleNestedPaths: {},
nested: {},
inherits: {},
callQueue: [Array],
_indexes: [Array],
methods: {},
statics: {},
tree: [Object],
query: {},
childSchemas: [],
plugins: [Array],
s: [Object],
options: [Object],
'$globalPluginsApplied': true },
collection:
NativeCollection {
collection: [Object],
opts: [Object],
name: 'bears',
collectionName: 'bears',
conn: [Object],
queue: [],
buffer: false,
emitter: [Object] },
Query: { [Function] base: [Object] },
'$__insertMany': [Function],
insertMany: [Function],
'$init': Promise { emitter: [Object], emitted: [Object], ended: false } } }
GET /api/bears/723d7fef-fdcf-435c-9148-8329ac372c3f 200 23.863 ms - 277
sorry, forgot to update the getById method to done a findOne instead.. notice I have an index on the bearId field so this is still quickl