When I try to implement the \’fetchCategories\’ part I get a status code 500 in the webapp and the following error in the backend terminal:
————————————————————————
C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\query.js:4891
const castError = new CastError();
^
CastError: Cast to ObjectId failed for value \”categories\” (type string) at path \”_id\” for model \”Book\”
at model.Query.exec (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\query.js:4891:21)
at model.Query.Query.then (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\query.js:4990:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
messageFormat: undefined,
stringValue: \’\”categories\”\’,
kind: \’ObjectId\’,
value: \’categories\’,
path: \’_id\’,
reason: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new BSONTypeError (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\bson\\lib\\error.js:41:28)
at new ObjectId (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\bson\\lib\\objectid.js:67:23)
at castObjectId (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\cast\\objectid.js:25:12)
at ObjectId.cast (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\schema\\objectid.js:246:12)
at ObjectId.SchemaType.applySetters (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\schematype.js:1201:12)
at ObjectId.SchemaType._castForQuery (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\schematype.js:1648:15)
at ObjectId.SchemaType.castForQuery (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\schematype.js:1636:15)
at ObjectId.SchemaType.castForQueryWrapper (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\schematype.js:1612:20)
at cast (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\cast.js:347:32)
at model.Query.Query.cast (C:\\Users\\barna\\Desktop\\Minden\\Egyetem\\Szakdolgozat\\react-project\\backend\\node_modules\\mongoose\\lib\\query.js:5319:12),
valueType: \’string\’
}
[nodemon] app crashed – waiting for file changes before starting…
————————————————————————
and this error in the frontend terminal:
————————————————————————
Proxy error: Could not proxy request /api/books/categories from localhost:3000 to http://localhost:5000/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
rs for more information (ECONNREFUSED).
Proxy error: Could not proxy request /api/books from localhost:3000 to http://localhost:5000/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
Proxy error: Could not proxy request /api/books/categories from localhost:3000 to http://localhost:5000/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
————————————————————————
Could someone please help me with this? I have checked the code over and over and I have no idea what the problem is. Here is my repository, the only changes in this are the codes added in this lesson in the App.js and bookRoutes.js (I\’m implementing a bookshop so some things are different in my code):