Cast to ObjectId failed for value on findById [closed]What's Mongoose error Cast to ObjectId failed for value XXX at path “_id”?Find document with array that contains a specific valueHow to resolve Mongoose Connect UNKNOWN?Why this error coming while running nodejs server?Angular client-side image upload into JSON document and saved to mongo through node/expressPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletMongoose pre.remove middleware of objects in array are never calledWhy express.Router() while separating routesHow to send github OAuth data to client?

On studying Computer Science vs. Software Engineering to become a proficient coder

What does this quote in Small Gods refer to?

How can a Lich look like a human without magic?

Is a diamond sword feasible?

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?

How are one-time password generators like Google Authenticator different from having two passwords?

What did Rocket give Hawkeye in "Avengers: Endgame"?

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

How can I answer high-school writing prompts without sounding weird and fake?

LocalDate.plus Incorrect Answer

"Fīliolō me auctum scito, salva Terentia"; what is "me" role in this phrase?

Why does a C.D.F need to be right-continuous?

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

Is there a faster way to calculate Abs[z]^2 numerically?

What are some possible reasons that a father's name is missing from a birth certificate - England?

Why can't RGB or bicolour LEDs produce a decent yellow?

What is the significance of 4200 BCE in context of farming replacing foraging in Europe?

What is the best way for a skeleton to impersonate human without using magic?

On what legal basis did the UK remove the 'European Union' from its passport?

We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?

How to pronounce "r" after a "g"?

Is it a Munchausen Number?

How to make the table in the figure in LaTeX?



Cast to ObjectId failed for value on findById [closed]


What's Mongoose error Cast to ObjectId failed for value XXX at path “_id”?Find document with array that contains a specific valueHow to resolve Mongoose Connect UNKNOWN?Why this error coming while running nodejs server?Angular client-side image upload into JSON document and saved to mongo through node/expressPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletMongoose pre.remove middleware of objects in array are never calledWhy express.Router() while separating routesHow to send github OAuth data to client?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is




"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report




const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");

mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());

app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);


thanks for any help!










share|improve this question













closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao Mar 23 at 12:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

    – Anthony Winzlet
    Mar 23 at 10:51












  • Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

    – Neil Lunn
    Mar 23 at 10:52

















0















I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is




"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report




const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");

mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());

app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);


thanks for any help!










share|improve this question













closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao Mar 23 at 12:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

    – Anthony Winzlet
    Mar 23 at 10:51












  • Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

    – Neil Lunn
    Mar 23 at 10:52













0












0








0








I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is




"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report




const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");

mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());

app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);


thanks for any help!










share|improve this question














I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is




"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report




const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");

mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());

app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);


thanks for any help!







node.js mongodb mongoose






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 10:44









GosmithGosmith

606




606




closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao Mar 23 at 12:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao Mar 23 at 12:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
If this question can be reworded to fit the rules in the help center, please edit the question.












  • l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

    – Anthony Winzlet
    Mar 23 at 10:51












  • Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

    – Neil Lunn
    Mar 23 at 10:52

















  • l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

    – Anthony Winzlet
    Mar 23 at 10:51












  • Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

    – Neil Lunn
    Mar 23 at 10:52
















l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

– Anthony Winzlet
Mar 23 at 10:51






l5c959036c3dfe2338412be8e is not a valid objectId. Remove the l from the begning of the id.

– Anthony Winzlet
Mar 23 at 10:51














Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

– Neil Lunn
Mar 23 at 10:52





Means what it says. l5c959036c3dfe2338412be8e is not valid for an ObjectId value. 5c959036c3dfe2338412be8e without the "l" on the beginning is however valid. I suggest a typo.

– Neil Lunn
Mar 23 at 10:52












1 Answer
1






active

oldest

votes


















0














Try removing the "I" from the objectId you pass as the param, as suggested in the comments.






share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try removing the "I" from the objectId you pass as the param, as suggested in the comments.






    share|improve this answer



























      0














      Try removing the "I" from the objectId you pass as the param, as suggested in the comments.






      share|improve this answer

























        0












        0








        0







        Try removing the "I" from the objectId you pass as the param, as suggested in the comments.






        share|improve this answer













        Try removing the "I" from the objectId you pass as the param, as suggested in the comments.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 11:46









        Moad EnnagiMoad Ennagi

        47048




        47048















            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript