Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am making my first project that is an e-commerce site with basic functionality.
When i click the first "BUT NOW" button I get an error. I have only programmed first button as a demo.
I am attaching a gist link and error is written in the comments section of gist.

https://gist.github.com/bisswolf/1e5212ec6c85ec33a61e87c0bf86af0e

What I have tried:

When i remove the "BUY NOW" button code it works fine but after writing code it doesn't work
Posted
Comments
CHill60 5-Aug-20 8:05am    
It is bad form to store your code on another site and expect us to go to that site to understand your problem. There is reams of code. Just post here the code that causes the problem and tell us what the error is
OriginalGriff 5-Aug-20 9:08am    
I'm not going to look at a whole project to try and work out where the relevant code is, or what might be wrong with it.

Instead, copy and paste your error info (message, stack trace, the whole thing) and then show us just the relevant fragments, indicating where the error occurs.
Then tell us what exactly you did (including data if it's involved at all) to cause the error, and what you have tried to find out what the problem is.

Help us to help you!

Use the "Improve question" widget to edit your question and provide better information.
divyanshu dalewani 5-Aug-20 9:26am    
The error is -
CastError: Cast to ObjectId failed for value "frontpage.css" at path "_id" for model "fashion"
at model.Query.exec (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\query.js:4351:21)
at model.Query.Query.findOne (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\query.js:2220:8)
at Function.findOne (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\model.js:2152:13)
at Function.findById (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\model.js:2090:15)
at C:\Users\divya\Desktop\Dynamic web\app.js:48:10
at Layer.handle [as handle_request] (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\index.js:281:22
at param (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\index.js:354:14)
at param (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\index.js:365:14)
at Function.process_params (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\index.js:410:3)
at next (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\index.js:275:10)
at urlencodedParser (C:\Users\divya\Desktop\Dynamic web\node_modules\body-parser\lib\types\urlencoded.js:91:7)
at Layer.handle [as handle_request] (C:\Users\divya\Desktop\Dynamic web\node_modules\express\lib\router\layer.js:95:5) {
messageFormat: undefined,
stringValue: '"frontpage.css"',
kind: 'ObjectId',
value: 'frontpage.css',
path: '_id',
reason: Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
at new ObjectID (C:\Users\divya\Desktop\Dynamic web\node_modules\bson\lib\bson\objectid.js:59:11)
at castObjectId (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\cast\objectid.js:25:12)
at ObjectId.cast (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\schema\objectid.js:267:12)
at ObjectId.SchemaType.applySetters (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\schematype.js:1070:12)
at ObjectId.SchemaType._castForQuery (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\schematype.js:1498:15)
at ObjectId.SchemaType.castForQuery (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\schematype.js:1488:15)
at ObjectId.SchemaType.castForQueryWrapper (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\schematype.js:1467:15)
at cast (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\cast.js:326:32)
at model.Query.Query.cast (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\query.js:4740:12)
at model.Query.Query._castConditions (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\query.js:1865:10)
at model.Query. (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\query.js:2122:8)
at model.Query._wrappedThunk [as _findOne] (C:\Users\divya\Desktop\Dynamic web\node_modules\mongoose\lib\helpers\query\wrapThunk.js:16:8)
at C:\Users\divya\Desktop\Dynamic web\node_modules\kareem\index.js:369:33
at processTicksAndRejections (internal/process/task_queues.js:79:11)
}
OriginalGriff 5-Aug-20 9:59am    
Read what I said again ...
divyanshu dalewani 7-Aug-20 10:55am    
This line is causing trouble -

app.get("/show/:id", function (req, res) {
fashion.findById(req.params.id, function (err, data) {
if (err) {
console.log(req.params.id);
} else {
res.render("show.ejs", { showw: data });
}
});
});

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900